event in relation with tracks changes...

Help each other out

Re: event in relation with tracks changes...

Postby dalanik on Wed Mar 26, 2008 8:20 am

Here it is, tested and all :-)

Code: Select all

Module Script

Private t As XTimer = new XTimer(5000)
Public SongOld, SongNew As String

Public Sub Main(Action As String)
   if (Action = "Start") then
      SongOld = Xlobby.GetXlobbyVar("audioplayer>now>%artist%")
      t.StartTimer
   Else if (Action = "Stop") then
      t.StopTimer
   End if
End Sub

End Module

Class XTimer

   ' *** The system timer
   Private t As System.Timers.Timer

   ' *** The class constructor
   Public Sub New(pElapsed As Integer)

      '  *** Initialize the timer
      t = new System.Timers.Timer(pElapsed)

      ' *** Add the event handler
      AddHandler t.Elapsed, AddressOf TimerFired
   End Sub

   ' *** Starts the timer
   Public Sub StartTimer()
      t.Enabled = true
   End Sub

   ' *** Stops the timer
   Public Sub StopTimer()
      t.Enabled = false
   End Sub

   ' **** Executes when the elapsed event occurs
   Public Sub TimerFired(ByVal Sender As Object, ByVal e As System.Timers.ElapsedEventArgs)

      SongNew = Xlobby.GetXlobbyVar("audioplayer>now>%artist%")

      if( SongNew <> SongOld ) Then
         Xlobby.SendCommand("category", "music", "artist", "audioplayer>now>%artist%")
         SongOld = SongNew
      End if
   End Sub
End Class

dalanik
 
Posts: 885
Joined: Mon Apr 19, 2004 12:35 pm
Location: Prague, Czech Republic

Re: event in relation with tracks changes...

Postby S Pittaway on Wed Mar 26, 2008 8:28 am

i havent used it for a while :) but xMusic lets you run an event group whenever a track changes (amoung other things)
http://xlobby.com/forum/viewtopic.php?f=14&t=5438


current.track.on track change command:xlobby command
Whenever the current track changes it will run "xlobby command".


That way you can get the event group working as you want then link it in to auto track changes using the command above.
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England

Re: event in relation with tracks changes...

Postby dalanik on Wed Mar 26, 2008 9:16 am

What method does XMusic use? I'm just asking because I'd also may have use for this and am trying to find most effective method... if it uses the timer, I might as well use Xscript?
dalanik
 
Posts: 885
Joined: Mon Apr 19, 2004 12:35 pm
Location: Prague, Czech Republic

Re: event in relation with tracks changes...

Postby S Pittaway on Wed Mar 26, 2008 12:26 pm

you have no choice but to use a timer... hopefully they will add a separate trigger for version 3?

i only mentioned it because it was already done and if you dont like coding....

Anyway, every second I do the following -

Code: Select all
    void CheckForTrackChanges()
    {
        if (xDB.GetString("audioplayer>now>%parameter%") != m_LastTrackParamater)
        {
          if (xDB.GetString("audioplayer>now>%parameter%") != m_LastTrackParamater)
          {
            string NewTrackParamater = xDB.GetString("audioplayer>now>%parameter%");
            if (NewTrackParamater != m_LastTrackParamater)
            {
              if (TrackParamater == "")
              {
                //NO TRACK PLAYING
              }
              else
              {
                //A NEW TRACK
                m_LastTrackParamater = NewTrackParamater;
            }
          }
        }
    }//CheckForTrackChanges



There is (was??) a bug in xlobby that caused it to return the old parameter even tho the track had changed so i had to get it several times to be sure... Did you notice it missing track changes with a single check?


BTW, have you missed out the "custom search" bit of the Xlobby.SendCommand("category", "music", "artist", "audioplayer>now>%artist%") :)
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England

Re: event in relation with tracks changes...

Postby dalanik on Wed Mar 26, 2008 12:39 pm

S Pittaway wrote:BTW, have you missed out the "custom search" bit of the Xlobby.SendCommand("category", "music", "artist", "audioplayer>now>%artist%") :)


Yes, I just noticed :-)( I was testing with MsgBox("A") :)
dalanik
 
Posts: 885
Joined: Mon Apr 19, 2004 12:35 pm
Location: Prague, Czech Republic

Re: event in relation with tracks changes...

Postby alamata on Wed Mar 26, 2008 12:58 pm

im afraid to abuse but...

i have copy the dalanik's code
but i have one error when i run the script

"invalid number of parameters passed to function : main" :shock:

dalanik wrote:
S Pittaway wrote:BTW, have you missed out the "custom search" bit of the Xlobby.SendCommand("category", "music", "artist", "audioplayer>now>%artist%") :)


where do i put the Xlobby.SendCommand("category", "music", "artist", "audioplayer>now>%artist%")

thanks for your comprehension...
alamata
 
Posts: 70
Joined: Thu Jan 11, 2007 12:03 pm

Re: event in relation with tracks changes...

Postby S Pittaway on Wed Mar 26, 2008 1:29 pm

try

Code: Select all

   Public Sub TimerFired(ByVal Sender As Object, ByVal e As System.Timers.ElapsedEventArgs)

      SongNew = Xlobby.GetXlobbyVar("audioplayer>now>%artist%")

      if( SongNew <> SongOld ) Then
         Xlobby.SendCommand("category", "custom search", "music", "artist", SongNew)
         SongOld = SongNew
      End if
   End Sub




I wanted to do something like this, but it does the search on ALL cats that map onto the music database, so if you are looking for a album and the track changes the music screen will change to only show the results from the search...
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England

Re: event in relation with tracks changes...

Postby dalanik on Wed Mar 26, 2008 1:44 pm

alamata wrote:"invalid number of parameters passed to function : main" :shock:


Ah, sorry, thought it was obvious from code. you need to pass the script parameter, either "Stop" or "Start". So when you execute XScript plugin with the scriptname.txt just add "Start" (separated from script filename with space, ofcourse) :)
dalanik
 
Posts: 885
Joined: Mon Apr 19, 2004 12:35 pm
Location: Prague, Czech Republic

Re: event in relation with tracks changes...

Postby alamata on Wed Mar 26, 2008 4:07 pm

well,... thanks for this information...

now the script can run... :wink:

but..
i have try severals times in differents ways
but without results.... :(

i have put the event concerning the script on the enter screen event of the screen menu...
but no changes at the change of the track...

do i have made something wrong....

is it possible that someone else test the code...

what is the exact definitif code...

thanks for your comprehension...
alamata
 
Posts: 70
Joined: Thu Jan 11, 2007 12:03 pm

Previous