Controlling mm5 via com object from external vb code/vbscript

To discuss development of addons / skins / customization of MediaMonkey v5 / v2024

版主: jiri, drakinite, Addon Administrators

回复
alex11110001
帖子: 2
注册时间: 周三 4月 09, 2025 2:42 am

Controlling mm5 via com object from external vb code/vbscript

帖子 由 alex11110001 »

The idea is simple: if mm is running, switch to the next track. I'm having a problem with the "mm is running" part. First, GetObject doesn't seem to work at all. This line throws "ActiveX component can't create object" runtime error:

代码: 全选

Set mm = GetObject(, "SongsDB5.SDBApplication")
Therefore I can't use it to check if mm is running - I have to call CreateObject regardless of whether mm is running or not. There's another problem - if the app is not running, calling CreateObject launches the app, but then the com interface stops working. Finally, there's SDBApplication.IsRunning flag, but it's always True for some reason.

代码: 全选

Dim mm
Set mm = CreateObject("SongsDB5.SDBApplication")  ' launches the mm
Debug.Print mm.IsRunning  ' prints True immediately, not even waiting for the mm to finish loading
mm.Player.Next  ' doesn't switch to the next track; sometimes no visible error, sometimes it's "Access violation at address..." in the mm
And if I leave the mm open and try running the code above the second time, vb throws a runtime error "Server execution failed" on CreateObject call. Oh, and if mm was launched normally (via double-clicking on a shortcut, for example), then the script works perfectly.

So, is it me or it's an mm's issue? What the right way or maybe a workaround?
Ludek
帖子: 5132
注册时间: 周五 3月 09, 2007 9:00 am

Re: Controlling mm5 via com object from external vb code/vbscript

帖子 由 Ludek »

Hi, a cross-platform way of controlling MM5 from external applications is via the Chrome Devtools API. You can find an explanation on how to use it with MediaMonkey here: viewtopic.php?p=447737#p447737
alex11110001
帖子: 2
注册时间: 周三 4月 09, 2025 2:42 am

Re: Controlling mm5 via com object from external vb code/vbscript

帖子 由 alex11110001 »

Hi,

it's all very interesting, but I'd rather use something I'm used to instead of learning a completely new toolset. There's also no need for it to be cross-platform, windows is enough.

Let me maybe rephrase the question, split it into two even. So I'm writing scripts that communicate with mm via com objects.
1. For scripts that require mm to be running, how do I check that? Can I do this using mm com objects, some other mm-specific method, or just search for MediaMonkey.exe process?
2. For scripts that are allowed to start mm if it's not yet running, before interacting with it, how do I do that? Again, is there some specific method? If not, and a script runs mm's executable, how it then knows when mm is loaded and ready to accept commands?

Thanks!
Ludek
帖子: 5132
注册时间: 周五 3月 09, 2007 9:00 am

Re: Controlling mm5 via com object from external vb code/vbscript

帖子 由 Ludek »

Reading this link

http://localhost:9222/json

to check whether MM is running and ready to accept commands is reliable method

As for checking MediaMonkey.exe process, this is not enough as MM5/2024 is based on Chromium engine and there are multiple MediaMonkeyEngine.exe processes (for rendering and network services)..

Especially the 'MediaMonkeyEngine.exe --type=renderer' is the process that needs to run for MM to be "ready"
alex11110001
帖子: 2
注册时间: 周三 4月 09, 2025 2:42 am

Re: Controlling mm5 via com object from external vb code/vbscript

帖子 由 alex11110001 »

That's useful, thank you. Though I mentioned MediaMonkey.exe, not MediaMonkeyEngine.exe, and it seems to have just one instance, at least at the moment.
上次由 alex11110001 在 周五 4月 11, 2025 11:44 am,总共编辑 1 次。
回复