Automate MM from VB - NOT VBScript

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Automate MM from VB - NOT VBScript

Postby tsadler » Sat Jul 03, 2004 4:47 pm

What I'd like to do is work with MM from Visual Basic. I read in the manual this section:
If you wish to access MediaMonkey's scripting functions from outside of MediaMonkey, (e.g. via an ASP page), you can create this object with the following code:

Dim SDB
Set SDB = CreateObject( "MediaMonkey.SDBApplication")

Note: “MediaMonkey init.vbs” file is always executed before your script and therefore contains some constants that may be used afterwards within your script.


When I try just those 2 lines of code, I get the error - "ActiveX component can't create object". I checked in the References and Components dialog boxes for MediaMonkey and Vertis and found nothing so I went to RegEdit and searched for "SDBApplication" and found an entry for "SongsDB.SDBApplication".

When I changed the 2nd line to:

Set SDB = CreateObject( "SongsDB.SDBApplication")

It worked fine. Is something wrong with my installation or the documentation?
[/quote]
tsadler
 

Postby Peke » Sat Jul 03, 2004 7:16 pm

Code: Select all
MediaMonkey.SDBApplication


Is not valid, but
Code: Select all
SongsDB.SDBApplication
Is

As 'SongsDB.SDBApplication' is registered as ActiveX Component.
There is possibility for update in future but for now use

Code: Select all
Set SDB = CreateObject( "SongsDb.SDBApplication")
Last edited by Peke on Sat Jun 25, 2005 10:17 pm, edited 2 times in total.
Best regards,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10434
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

Postby Lowlander » Mon Jul 05, 2004 12:42 pm

I'm using this code

Code: Select all
<%
Dim SDB
Set SDB = CreateObject( "SongsDB.SDBApplication")
If SDB.Player.isPlaying And Not SDB.Player.isPaused Then
 response.write "MM is playing now "
End If
%>


in ASP. I have also tried to change SongsDB to MediaMonkey but neither versions work. In both cases the page stays loading forever.

What am I doing wrong?


PS I'm trying to interface with MM from ASP, this is just a test setup.
Lowlander (MediaMonkey user since 2003)
Lowlander
 
Posts: 43393
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Postby mockturtle » Tue Jul 06, 2004 3:38 pm

You are right, it's an error in documentation, the correct name to be used really is 'SongsDB.SDBApplication'.

Thanks,
Jiri
mockturtle
 
Posts: 8
Joined: Wed Jun 18, 2008 4:49 pm

Same

Postby gratajik » Sat Jun 25, 2005 4:31 pm

Also have a problem with this:

Set SDB = CreateObject("SongsDB.SDBApplication")
Set Tree = SDB.MainTree

I see the icon for MediaMonkey come up on the task list, but the call never returns unless I kill media monkey - which causes a Can't Create ActiveX Component.

If MM is already up it works.... any ideas?
gratajik
 
Posts: 10
Joined: Tue Apr 19, 2005 11:40 pm

Postby Peke » Sat Jun 25, 2005 10:09 pm

I also pointed Jiri For that bug and after intesive tests we found that Windows do not Create ComObject fast enough when calling within Common ComObject functions. I personaly solve this Issue with This piece of Code:
Code: Select all
    MMPath := 'c:\Program Files\MediaMonkey'
    Begin
      If Findwindow('TFMainWindow','MediaMonkey') > 0 Then
        Begin
          SDB := CreateOleObject('SongsDB.SDBApplication');
        End
      Else
        Begin
          // Check For existance of MM Path
          If MMPath <> '' Then
            Begin
              ShellExecute (0, 'open', Pchar('MediaMonkey.exe'),nil, Pchar(MMPath), SW_SHOW);
              While Findwindow('TFMainWindow','MediaMonkey') = 0 Do
                Begin
                End;
              SDB := CreateOleObject('SongsDB.SDBApplication');
            End
          Else
            Exit;
        End;
    End;

After This SDB is initialized As it soposed to be and MM is started Normaly
I Hope It helps even it is Delphi Code.
Best regards,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10434
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

Yeah...

Postby gratajik » Sun Jun 26, 2005 11:56 am

That was what I was afraid of :) Do-able, buy annoying.

Now if I can get a answer on this (http://www.mediamonkey.com/forum/viewto ... highlight=), I'll get StationRipper talking to media monkey :P
gratajik
 
Posts: 10
Joined: Tue Apr 19, 2005 11:40 pm

Postby gratajik » Sun Jun 26, 2005 7:09 pm

It could be installed anywhere... anyone know of a 100% way to tell where? Only way I've seen is something like this:


If FindWindow("TFMainWindow", "MediaMonkey") > 0 Then
'
' Get the path to Media Monkey and Open it
'
Set WSHShell = CreateObject("WScript.Shell")
sMMPath = WSHShell.RegRead("HKEY_CLASSES_ROOT\Applications\MediaMonkey.exe\shell\open\Command\")
If sMMPath <> "" Then
WSHShell.Exec (sMMPath)
End If


End If
gratajik
 
Posts: 10
Joined: Tue Apr 19, 2005 11:40 pm

Postby Peke » Sun Jun 26, 2005 11:00 pm

Try this, if this does not work then ask someone that have more expt than me. I found that API FindWindow can't be used with VBScripting during Security Issue. This Do something similar But...
Code: Select all
Dim SDB, WSHShell, MMpath, Command, Result
Set WSHShell = CreateObject("WScript.Shell")
If WSHShell.AppActivate("MediaMonkey") = False Then
  MMpath = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MediaMonkey_is1\InstallLocation")
  If MMPath <> "" Then
    Command = Chr(34)&MMpath&"mediamonkey.exe"&Chr(34)
    Result = WSHShell.Run(Command,1,0)
    While  WSHShell.AppActivate("MediaMonkey") = False
    Wend
    Set SDB = CreateObject("SongsDB.SDBApplication")
    SDB.ShutdownAfterDisconnect = False
    SDB.Player.Play
  End If
Else
  Set SDB = CreateObject("SongsDB.SDBApplication")
  SDB.ShutdownAfterDisconnect = False
  SDB.Player.Play
End If


I would like to see someone get this to work 100%.

One More thing do you use Windows Scripting Host or you make program in VB I got little bit confused with your other posts.
Best regards,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10434
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

Postby mockturtle » Mon Jun 27, 2005 1:45 am

Actually I found out that the creation of Application object wasn't done properly, it will be improved in the next release. Then the following code should be ok in any case:

Dim SDB
Set SDB = CreateObject( "SongsDB.SDBApplication")
While Not SDB.IsRunning
WEnd
SDB.Player.Play
SDB.ShutdownAfterDisconnect = False

Jiri
mockturtle
 
Posts: 8
Joined: Wed Jun 18, 2008 4:49 pm

Re: Automate MM from VB - NOT VBScript

Postby pjokkis » Mon Dec 19, 2011 11:20 am

Do you know if this is supposed to work in MM version 4?

I have put the following code in an aspx-page, but it does not work on my system:
Code: Select all
<%
Dim SDB as Object
SDB = CreateObject( "SongsDB.SDBApplication" )

If SDB.Player.isPlaying And Not SDB.Player.isPaused Then
   response.write("MM is playing now ")
End If
%>


I get the error "System.Exception: Can not create ActiveX component."


Pål.
pjokkis
 
Posts: 2
Joined: Sun Dec 11, 2011 10:02 am

Re: Automate MM from VB - NOT VBScript

Postby pgrimmer » Wed Dec 21, 2011 3:25 am

I am able to access the MediaMonkey API fairly easily. What I show below I did in VBA in Excel but I am sure it will also work in VB6. I don't do .NET but I suspect it will work with the newer versions of Visual Basic too. I did this using MediaMonkey version 4.0.1 but I don't think that matters.

In the VBA editor go to Tools | References and add "MediaMonkey Library" (the "location" tag below should show the path to MediaMonkey.exe).

Insert a module and put this code in it:

Code: Select all
Sub Test1()
Dim SDB1 As SongsDB.SDBApplication
Set SDB1 = New SongsDB.SDBApplication
With SDB1
   If .Player.isPlaying Then
      If .Player.isPaused Then
         MsgBox "MM is running but paused now!"
         End If
      End If
   End With
End Sub


When yo run this sub, if MM is running and paused then you get a MsgBox telling you that. It's simple but it shows how to bind with the library. I looked all over my C: drive for something "SongsDB" until I figured out it is contained within MediaMonkey.exe and this COM object is available through References.

If you want to see all of the objects that are available to you, press F2 to bring up the Object Browser and select the library "SongsDB" and it will show all of the classes, members, enumeratinos etc. that you can use.

I suggest that you do NOT use the CreateObject method. It causes the SongsDB to be bound to your code at compile time ("late binding") and not at design time ("early binding"). What that means in plain English is that when you use the References route I described then you get the IntelliSense stuff (the options after you enter a dot, object browser stuff etc.) which you do not get if you use CreateObject. The other advantage is that the code runs a lot faster because you bind well before the code is executed. I don't use scripting but if I remember correctly you have to use CreateObject there (NOT in a "real" language) because the scripting languages do not do a compile and so do not have early binding capability.
pgrimmer
 
Posts: 15
Joined: Thu Jun 26, 2008 12:19 am

Re: Automate MM from VB - NOT VBScript

Postby Clouseau » Tue Apr 04, 2017 10:01 am

I know this is "ancient history" but I stumbled here trying to fix an issue with a script calling CreateObject("SongsDB.SDBApplication") and wanted to share my solution.

The main issue I was having stemmed from the fact that I was running MediaMonkey as a portable application. Because of this, the SongsDB.SDBApplication wasn't registered and therefore could not be instantiated by the code. I searched the registry of a system that had MM installed for needed entries and came up with the following registry file that added just enough to get the script working.

NOTE: the paths would need to be modified to match the location in which you currently have MediaMonkey.exe installed, for my needs it is set to "X:\MediaMonkey4\MediaMonkey.exe"

Code: Select all
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\SongsDB.SDBApplication]
@="SDBApplication Object"

[HKEY_CLASSES_ROOT\SongsDB.SDBApplication\Clsid]
@="{148F7BB6-4943-4C53-8E30-0F9115D30283}"



[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{148F7BB6-4943-4C53-8E30-0F9115D30283}]
@="SDBApplication Object"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{148F7BB6-4943-4C53-8E30-0F9115D30283}\LocalServer32]
@="X:\\Program Files\\MediaMonkey4\\MediaMonkey.exe"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{148F7BB6-4943-4C53-8E30-0F9115D30283}\ProgID]
@="SongsDB.SDBApplication"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{148F7BB6-4943-4C53-8E30-0F9115D30283}\TypeLib]
@="{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{148F7BB6-4943-4C53-8E30-0F9115D30283}\Version]
@="1.0"



[HKEY_CLASSES_ROOT\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}]

[HKEY_CLASSES_ROOT\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}\1.0]
@="MediaMonkey Library"

[HKEY_CLASSES_ROOT\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}\1.0\0]

[HKEY_CLASSES_ROOT\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}\1.0\0\win32]
@="X:\\Program Files\\MediaMonkey4\\MediaMonkey.exe"

[HKEY_CLASSES_ROOT\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}\1.0\FLAGS]
@="0"

[HKEY_CLASSES_ROOT\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}\1.0\HELPDIR]
@="X:\\Program Files\\MediaMonkey4\\"



[HKEY_CLASSES_ROOT\Wow6432Node\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}]

[HKEY_CLASSES_ROOT\Wow6432Node\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}\1.0]
@="MediaMonkey Library"

[HKEY_CLASSES_ROOT\Wow6432Node\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}\1.0\0]

[HKEY_CLASSES_ROOT\Wow6432Node\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}\1.0\0\win32]
@="X:\\Program Files\\MediaMonkey4\\MediaMonkey.exe"

[HKEY_CLASSES_ROOT\Wow6432Node\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}\1.0\FLAGS]
@="0"

[HKEY_CLASSES_ROOT\Wow6432Node\TypeLib\{E602ED16-8EF9-4F08-B09F-6F6E8306C51B}\1.0\HELPDIR]
@="X:\\Program Files\\MediaMonkey4\\"
Clouseau
 
Posts: 10
Joined: Sat Jan 03, 2009 3:36 pm


Return to Need Help with Addons?

Who is online

Users browsing this forum: Google [Bot] and 13 guests