INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: RESOLVED: Problem retrieving Playing now list in Plugin  (Read 3678 times)

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
RESOLVED: Problem retrieving Playing now list in Plugin
« on: January 23, 2007, 12:45:02 pm »

I'm trying to develop a plugin for tag management.
I've used Mr Chriz' template plugin for VB.net, and looks like it works well. Even with MC 12.

At this point I can do all sorts of things except for interacting with the library or playlists.
What I want to do is to make my plugin retrieve all tracks from playing now, to a listbox or similar.

I have searched the developer pages, but have a problem finding the right piece of code.
Would really appreciate it if someone could point me in the right direction or show me an example or two.
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Problem retrieving Playing now list in Plugin
« Reply #1 on: January 23, 2007, 03:50:25 pm »

I have some C# code that does this, so I've converted it into VB,
although I've not got time to test it, so this is from memory effectively.

You may have to play around a bit but you should get the picture
I'm used to VB6 rather than .NET so a few things may have changed for example.
--------------------------------------------------------
       'Get the current playing now playlist
        Dim playlist as MediaJukebox.IMJCurPlaylistAutomation playlist;
        Set playlist = mediaCenterInterface.GetCurPlaylist ( )
       
        'Iterate through all the files in the playlist
        for (counter = 0 to playlist.GetNumberFiles() )
       
            'Get the file from the current position in the playlist
            dim track as MediaJukebox.MJFileAutomation
            set track = playlist.GetFile(counter)

            'Get the tracks filename
            dim trackFileName as string = track.Filename

            'Print the trackname
            call debug.print (trackFileName)
        next
----------------------------------------------------------

If only I had my .NET Script Plugin working I'd be able to test it...
Must get back to that sometime =)

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: Problem retrieving Playing now list in Plugin
« Reply #2 on: January 23, 2007, 05:36:42 pm »

I tried to modify your example to Visual Studio 2005, but didn't get far.
The problem now is that mediaCenterInterface is not declared. What should it be declared as?
Sorry. Only used to string, integer, char etc. Have to admit this is a bit beyond my capabilities...

If only I had my .NET Script Plugin working I'd be able to test it...

I've tried to integrate your suggestion in the template. Only have to build the project in Visual Studio 2005 and run MC.
You can download it here if you have the time to take a quick look at it: kirkegata.com\div\mc_vbnetplugintemplate.rar

Or just tell me what the hell i'm doing from the example under. Trying to get the playlist in some kind of box.
I might have just screwed it up more...

-------------------------------------------------------------------------------------------------------

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Get the current playing now playlist
        Dim playlist As MediaJukebox.MJCurPlaylistAutomationClass
        playlist = mediaCenterInterface.GetCurPlaylist()

        'Iterate through all the files in the playlist
        For counter = 0 To playlist.GetNumberFiles()

            'Get the file from the current position in the playlist
            Dim track As MediaJukebox.MJFileAutomation
            track = playlist.GetFile(counter)

            'Get the tracks filename
            Dim trackFileName As String = track.Filename

            'Print the trackname
            Call Debug.Print(trackFileName)
        Next
    End Sub
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Problem retrieving Playing now list in Plugin
« Reply #3 on: January 23, 2007, 05:42:21 pm »

Sorry in the VB plugin I appear to have refered to it as mediaCenterRef
Try changing mediaCenterInterface to me.mediaCenterRef

Hang in there, all will become clear soon I think!

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: Problem retrieving Playing now list in Plugin
« Reply #4 on: January 24, 2007, 03:00:35 pm »

I hope it will too. Thanks for being so patient ChriZ
It got me a little further though.. Still got a couple of errors. 3 years without programming does something with your memory. Even the little things I knew. I ended up with this:

-----------------------------------------------------------------------------------
  Dim playlist As String (Something I tested. Obviously wrong)
  Dim counter As Integer (Something I tested. Might be wrong)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim playlist As MediaJukebox.IMJCurPlaylistAutomation playlist (end of statement expected)
        playlist = Me.mediaCenterRef.GetCurPlaylist()

        For counter = 0 To playlist.GetNumberFiles() (GetNumberFiles not member of 'String')

            Dim track As MediaJukebox.MJFileAutomation
            track = playlist.GetFile(counter) (GetFile not member of 'String')

            Dim trackFileName As String = track.Filename

            Call Debug.Print(trackFileName)
        Next
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Problem retrieving Playing now list in Plugin
« Reply #5 on: January 24, 2007, 04:50:51 pm »

OK I just done a quick compile of this, and it compiled ok:
-----------------------------------------------------
                   'Get the current playing now playlist
            Dim counter As Integer 'You're correct  I forgot to define this one
            Dim playlist As MediaJukebox.MJCurPlaylistAutomationClass 'Should be OK
            playlist = mediaCenterRef.GetCurPlaylist()

            Dim listOfTrackNames As String = ""
            'Iterate through all the files in the playlist
            For counter = 0 To ( playlist.GetNumberFiles() - 1 ) 'Out by 1 problem was here

                'Get the file from the current position in the playlist
                Dim track As MediaJukebox.MJFileAutomation
                track = playlist.GetFile(counter)

                'Get the tracks filename
                Dim trackFileName As String = track.Filename

                'Create a list of track names
                listOfTrackNames = listOfTrackNames + vbCrLf + trackFileName

            Next
            MessageBox.Show(listOfTrackNames)
-----------------------------------------------
I Changed this one to use a messagebox instead of Debug.Print since
I'm not sure Debug.Print will actually show you anything given that
there's no output window.

You'll have to excuse me, I'm really short on time at the moment, alot of work
on else I'd come up with something more helpful,
hopefully that will allow you see that you've got a list of tracks however (Presuming theres some tracks in there)

If you get any more errors let me know.
If it compiles ok and you're getting problems with run time errors, let me know
and I'll point out how you can debug the plugin while it's running in MC.

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: Problem retrieving Playing now list in Plugin
« Reply #6 on: January 25, 2007, 05:51:22 am »

I know, time is precious.... Go with your own pace. I'm not in a hurry.

The compiling was ok now. Started the plugin and ended up with a Object reference error though  :o
I'm afraid it don't tell me much. Pasting the result here:

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at MC_VBNETPlugin_Template.MainInterface.MainInterface_Load(Object sender, EventArgs e) in D:\mc_vbnetplugintemplate\VB_NetPluginSoloution\VB_NetPluginProject\MainInterface.vb:line 54
   at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
   at System.Windows.Forms.UserControl.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.UserControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ActiveXImpl.System.Windows.Forms.IWindowTarget.OnM essage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
MC_VBNETPlugin_Template
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///D:/mc_vbnetplugintemplate/VB_NetPluginSoloution/VB_NetPluginProject/bin/Release/MC_VBNETPlugin_Template.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Accessibility
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
MediaJukebox
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///D:/mc_vbnetplugintemplate/VB_NetPluginSoloution/VB_NetPluginProject/bin/Release/MediaJukebox.DLL
----------------------------------------
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Problem retrieving Playing now list in Plugin
« Reply #7 on: January 25, 2007, 07:49:02 am »

If you go to Tools->Options->Text Editor->Basic
within Visual Studio you should see an option to turn on Line Numbering.
Do this, and then see if you can find line 54.

You've got something trying to happen in the panels load event.

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: Problem retrieving Playing now list in Plugin
« Reply #8 on: January 25, 2007, 10:53:27 am »

Yea. I know. Just forgot to tell wich line it was. Here it is. Marked in read.
Something needs to be done with the mediaCenterRef or what? Not sure what object the error refers to.

----------------------------------------------------------------------------------------------------------------
Private Sub MainInterface_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Get the current playing now playlist
        Dim counter As Integer 'You're correct  I forgot to define this one
        Dim playlist As MediaJukebox.MJCurPlaylistAutomationClass 'Should be OK
        playlist = mediaCenterRef.GetCurPlaylist()

        Dim listOfTrackNames As String = ""
        'Iterate through all the files in the playlist
        For counter = 0 To (playlist.GetNumberFiles() - 1) 'Out by 1 problem was here

            'Get the file from the current position in the playlist
            Dim track As MediaJukebox.MJFileAutomation
            track = playlist.GetFile(counter)

            'Get the tracks filename
            Dim trackFileName As String = track.Filename

            'Create a list of track names
            listOfTrackNames = listOfTrackNames + vbCrLf + trackFileName

        Next
        MessageBox.Show(listOfTrackNames)
    End Sub
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Problem retrieving Playing now list in Plugin
« Reply #9 on: January 25, 2007, 11:15:04 am »

Does the same error occur if that code is put back behind a button press?
I suspect the forms load event is occuring before the initialization from MC.
So the refrence to the Media Center object isn't ready to be used yet.


Make sure that the init method still looks something like this->
___________________________________________________
    ' <summary>
    ' After the plugin has been created Media Center
    ' will call the following method, giving us a reference
    ' to the Media Center interface.
    ' </summary>
    ' <param name="mediaCenterReference">
    ' Media Center Reference
    ' </param>       
Public Sub init(ByVal mediaCenterRef As MediaJukebox.MJAutomation)
      Try
          Me.mediaCenterRef = mediaCenterRef
      Catch ex As Exception
          MessageBox.Show("Failed loading plugin (Name of Plugin Here)/n Exception Thrown: /n" + ex.ToString())
'On reflection message in template isn't complete here, so here's a better version but it won't make any difference as long as the plugin is working
      End Try
End Sub
___________________________________________________

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: Problem retrieving Playing now list in Plugin
« Reply #10 on: January 25, 2007, 01:42:30 pm »

The loading of the plugin is not the problem.
Still get an error, but a different one, if I use a button to initialize the code.

Here's the message:

************** Exception Text **************
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'MediaJukebox.MJCurPlaylistAutomationClass'. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type. Instances of this type cannot be cast to any other class; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
   at MC_VBNETPlugin_Template.MainInterface.Button1_Click(Object sender, EventArgs e) in D:\mc_vbnetplugintemplate\VB_NetPluginSoloution\VB_NetPluginProject\MainInterface.vb:line 54

The rest remains the same. It points to the exact same line
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Problem retrieving Playing now list in Plugin
« Reply #11 on: January 25, 2007, 03:23:28 pm »

Sorry not sure where I copied that original code from but it was wrong
try changing line 53 to
Dim playlist As MediaJukebox.IMJCurPlaylistAutomation

I promise you it will get simpler than this in the end, I seem to be having a few brain dead moments.  ::)

KingSparta

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 20048
Re: Problem retrieving Playing now list in Plugin
« Reply #12 on: January 26, 2007, 05:42:03 am »

Another thing that may help coding is AxTools for VB Net
Logged
Retired Military, Airborne, Air Assault, And Flight Wings.
Model Trains, Internet, Ham Radio
https://MyAAGrapevines.com
Fayetteville, NC, USA

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Problem retrieving Playing now list in Plugin
« Reply #13 on: January 26, 2007, 06:01:25 am »

Another thing that may help coding is AxTools for VB Net


Hmm that does look quite interesting. Especially the code flow explorer.

KingSparta

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 20048
Re: Problem retrieving Playing now list in Plugin
« Reply #14 on: January 26, 2007, 11:17:05 am »

I have Used It For About 3 Years..

It will also check for dead code, Dead Vars and will analyze your code to ensure it runs fast, it will make some changes for you, some changes you must make manually.

"$Mid" Runs Faster Than "Mid" etc....
Logged
Retired Military, Airborne, Air Assault, And Flight Wings.
Model Trains, Internet, Ham Radio
https://MyAAGrapevines.com
Fayetteville, NC, USA

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: Problem retrieving Playing now list in Plugin
« Reply #15 on: January 27, 2007, 05:14:59 am »

It finally worked!

For the rest of you who might wonder what the actual code was at the end:

-----------------------------------------------------------------------------------------------------------
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Get the current playing now playlist
        Dim counter As Integer 'You're correct  I forgot to define this one
        'Dim playlist As MediaJukebox.MJCurPlaylistAutomationClass 'Should be OK
        Dim playlist As MediaJukebox.IMJCurPlaylistAutomation
        playlist = mediaCenterRef.GetCurPlaylist()

        Dim listOfTrackNames As String = ""
        'Iterate through all the files in the playlist
        For counter = 0 To (playlist.GetNumberFiles() - 1) 'Out by 1 problem was here

            'Get the file from the current position in the playlist
            Dim track As MediaJukebox.MJFileAutomation
            track = playlist.GetFile(counter)

            'Get the tracks filename
            Dim trackFileName As String = track.Filename

            'Create a list of track names
            listOfTrackNames = listOfTrackNames + vbCrLf + trackFileName

        Next
        MessageBox.Show(listOfTrackNames)
    End Sub
--------------------------------------------------------------------

Combine it with ChriZ' .Net Plugin template and you have a small but functional plugin with playlist import.

I'll test the AxTools later King. Looks promising.

Thanks alot for your help ChriZ! Could not have done it without you!
Logged
- I may not always believe what I'm saying

KingSparta

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 20048
Re: Problem retrieving Playing now list in Plugin
« Reply #16 on: January 27, 2007, 03:30:51 pm »

Note: I Got A Discount On AxTools, Because I Asked For One.

They Had To Make A Special Link For Me To Buy...

I Told Them I Just Play With Code As A Hobby

I Still Paid A Chunk Of Change, But If You Don't Ask You Will Never Know..

Logged
Retired Military, Airborne, Air Assault, And Flight Wings.
Model Trains, Internet, Ham Radio
https://MyAAGrapevines.com
Fayetteville, NC, USA
Pages: [1]   Go Up