INTERACT FORUM

Please login or register.

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

Author Topic: How to make Visual Basic plugin reflect track playing  (Read 2923 times)

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
How to make Visual Basic plugin reflect track playing
« on: February 12, 2007, 09:37:38 am »

I want my selected index in a listbox to change when I change tracks. I think Mr ChriZ' EvilLyrics does something similar.
My other option is to make a Next/Previous button in the plugin, and then change the song in playing now according to the selected index in the listbox.

I could need an example. I appologize my problem when it comes to understanding the automation/interaction part.
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: How to make Visual Basic plugin reflect track playing
« Reply #1 on: February 12, 2007, 10:05:23 am »

Howdie I did get your message yesterday.
I will try to post some code later but currently quite busy,
so it might not happen till tomorrow.

Using MC12 it's theoretically possible to do using
events, however the Plugin Templates have not been
updated for this yet, and so at the moment it has
to be done by Polling.
Will explain more later.

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: How to make Visual Basic plugin reflect track playing
« Reply #2 on: February 12, 2007, 10:41:31 am »

Great. No problem at all.
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: How to make Visual Basic plugin reflect track playing
« Reply #3 on: February 15, 2007, 06:00:54 pm »

Created a VB version but it's not quite working properly,
so i'll have to finish it tomorrow.  VB.NET's got some nice quirk's!

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: How to make Visual Basic plugin reflect track playing
« Reply #4 on: February 16, 2007, 11:39:14 am »

Again, no problem. I tried a bit my self, but ran into a problem or two.
It all depends on you now  :D
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: How to make Visual Basic plugin reflect track playing
« Reply #5 on: February 16, 2007, 02:15:23 pm »

OK I've added a sample script to the Script Plugin Scripts
which shows how to see the current playing track in VB.NET
http://yabb.jriver.com/interact/index.php?topic=33020.msg265278#msg265278

It's a good example of the power of .NET scripts with
the ability to use Delegates and Events.

I've discovered one bug and one flaw in the Script Plugin however.
Renaming VB scripts turns them into C# Scripts (unfortunatley without conversion!).

Will sort this out over the weekend hopefully.
Also The Script Plugin can only terminate the initial thread
of the script, so I probably need a better way of doing this.

The script contains a class which you can attach an event
to, which will return you the latest track, every time the track
changes.  You can insert this as a new class in your project,
and then use it as you wish.

The script shows how the class is used.

I won't be around much over the next week.  I'm going to Prison.

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: How to make Visual Basic plugin reflect track playing
« Reply #6 on: February 18, 2007, 06:42:51 am »

Thanks for the example. Pretty huge for such a simple task aint it?

Your code seems to do alot more than I was thinking of... Here is my plan:
  • Check track playing each 0,5 sec and get index for playing now
  • Check the index against the index in the plugins playlist
  • If wrong then change selected index

On to the problem I faced. I guess my problem is to understand where I actually activate it?? I've tried to put it in an own module. And I've tried to call the sub's and class and I don't know what in it. Even put in a assload of Messagebox.Text(variables) to check if anything trigges. But no.

My other problem would be to understand the difference between IMJ...Automation and the previout MJ...Automation I have been using.

In meantime I'll try a code that skips track when I hit a button in my plugin. Would be alot easier I guess.
Not sure how far I will get, so if you feel like posting an example for that too, please do.

Prison ey? Not sure I want to know more  :)
Good luck! Hope you get out sooner than later.
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: How to make Visual Basic plugin reflect track playing
« Reply #7 on: February 18, 2007, 08:10:26 am »

Thanks for the example. Pretty huge for such a simple task aint it?

Your code seems to do alot more than I was thinking of... Here is my plan:
  • Check track playing each 0,5 sec and get index for playing now
  • Check the index against the index in the plugins playlist
  • If wrong then change selected index

On to the problem I faced. I guess my problem is to understand where I actually activate it?? I've tried to put it in an own module. And I've tried to call the sub's and class and I don't know what in it. Even put in a assload of Messagebox.Text(variables) to check if anything trigges. But no.

My other problem would be to understand the difference between IMJ...Automation and the previout MJ...Automation I have been using.

In meantime I'll try a code that skips track when I hit a button in my plugin. Would be alot easier I guess.
Not sure how far I will get, so if you feel like posting an example for that too, please do.

Prison ey? Not sure I want to know more  :)
Good luck! Hope you get out sooner than later.

Doesn't really matter where you put the class, in it's own module should be fine.
Then where you want to use it create an instance of that class

Dim trackFinderResource as New TrackFinder(mediaCenterReference)

Then add the event handler to it
AddHandler QuickTest.TrackChange, AddressOf nameOfEventHandlerHere

Create the event handler

Private Sub trackFinderResource _TrackChanged(track as IMJFileAutomation)
        'Do what ever you want with the track here....
End Sub

It starts working the moment the object is created.
I in front of the objects refers to the fact it's an Interface rather than a
class reference.  (You'll have to look in to OO a bit more if you want to
find more about that).

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: How to make Visual Basic plugin reflect track playing
« Reply #8 on: February 19, 2007, 04:43:35 pm »

I actually thought I could do this:

Public playback As MediaJukebox.IMJPlaybackAutomation

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       playback.Next()
End Sub


Can anybody tell me what I'm doing wrong?
Can't be that hard to make a button skip to the next track right?
Logged
- I may not always believe what I'm saying

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: How to make Visual Basic plugin reflect track playing
« Reply #9 on: February 27, 2007, 04:01:39 am »

I actually thought I could do this:

Public playback As MediaJukebox.IMJPlaybackAutomation

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       playback.Next()
End Sub


Can anybody tell me what I'm doing wrong?
Can't be that hard to make a button skip to the next track right?

You've created an interface, but it doesn't in anyway reference
the Media Center interface.

If you imagine an interface as like a remote control to your telly,
the telly is Media Center.  In order for the remote control to work
the remote needs to point at the telly.

The remote control doesn't care how the telly works, it just tells the telly
to change channels etc.  This means Media Center can change behind the
scenes but you still use the same interface.

Moving the an analergy a bit further.  Imagine the the remote is not
an infra red remote but a radio remote.  Now it doesn't need to point
at the telly at all, but it does need to be on the same frequency as
the telly.

What you've done is to create a remote, but the frequency isn't pointed
at the telly.

Luckilly for us the Telly can tell us what Frequency it's on.
Ie Media Center will give us a reference to talk on. 

This is a simplified view, behind the scenes there's a whole world
of things to learn about pointers/references etc, but that maybe
enough to keep you going.

Unfortunatley I'm not in front of a development machine but what I think
you want to do is something like this
   'Get new Interface Pointer
  playback = me.mediaCenterReference.GetPlayBack()

  'Change to next track
  playBack.Next()

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: How to make Visual Basic plugin reflect track playing
« Reply #10 on: March 13, 2007, 04:25:03 pm »

Wow! Thanks. You are my hero. Right next to Chuck Norris.
Think I understand the connection a little better now.

The result ended up like this:

    Public playback As MediaJukebox.IMJPlaybackAutomation
    Public playingNowPosition As Integer
    Public playbackState As Integer

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        'Findig the play state (stopped, playing or paused)
        playbackState = mediaCenterRef.GetPlayback.State
        'Get new Interface Pointer
        playback = Me.mediaCenterRef.GetPlayback()

        If playbackState = 0 Then
            'Start playing
            playback.Play()
        ElseIf playbackState = 1 Then
            'Resume playing
            playback.Pause()
        Else
            'Change to next track
            playback.Next()
        End If

        playingNowPosition = mediaCenterRef.GetPlayback.Position()

        lb_playlist.SelectedIndex = playingNowPosition

    End Sub

Only problem I got now is marked in red. Can't get the right position of the selected track in playing now. Tried alot of different tactics now :-[ In the example above the the first track (0) is allways selected. I also tried:  playingNowPosition = playback.Position()
What am I missing here!?
Logged
- I may not always believe what I'm saying

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: How to make Visual Basic plugin reflect track playing
« Reply #11 on: March 20, 2007, 01:12:52 pm »

Never mind. I finally figured it out my self!

 Public playlist As MediaJukebox.IMJCurPlaylistAutomation
 
 playlist = mediaCenterRef.GetCurPlaylist()
 Dim playingNowPosition as Integer = playlist.Position
Logged
- I may not always believe what I'm saying
Pages: [1]   Go Up