Fire event on media change

Help each other out

Fire event on media change

Postby fletch on Fri Dec 08, 2006 7:32 pm

Is there a way to have an event fire when the currently playing media changes. For example when the currently playing song in a playlist changes to the next can an event be setup to execute?

Aaron
fletch
 
Posts: 64
Joined: Sun Feb 05, 2006 1:11 am
Location: Castle Rock, CO

Postby Bill Lott on Mon Dec 11, 2006 6:21 pm

bump...

This would be helpful. Anyone know how to do it?
Bill Lott
 
Posts: 293
Joined: Sun Sep 05, 2004 3:25 pm
Location: Louisville, KY

Postby P3rv3rt B3ar on Mon Dec 11, 2006 6:50 pm

Bill Lott wrote:This would be helpful. Anyone know how to do it?


Yes it would be helpful, as far as i know it doesnt exist, but it can be done with plugin, which would inspect nowplaying variable periodicly by comparing it to old value and fire event when it has changed... by making period small enough, needed precision could be achieved.
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Postby bmblank on Mon Dec 11, 2006 6:52 pm

Hey, that was my idea!
bmblank
 
Posts: 233
Joined: Fri Jun 30, 2006 12:55 pm

Postby P3rv3rt B3ar on Mon Dec 11, 2006 9:14 pm

bmblank wrote:Hey, that was my idea!


sorry, did i steal it :)

well u can have it, i have my hands full with my own ideas :)
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Postby bmblank on Mon Dec 11, 2006 9:27 pm

I'm just an idea man, I don't know how to program shiznit!
bmblank
 
Posts: 233
Joined: Fri Jun 30, 2006 12:55 pm

Postby Bill Lott on Tue Dec 12, 2006 3:20 am

I was hoping it was an undefined xl variable. Since I'm not much at scripting I hope someone can post an example (P3rv3rt B3ar :D )
Bill Lott
 
Posts: 293
Joined: Sun Sep 05, 2004 3:25 pm
Location: Louisville, KY

Postby S Pittaway on Tue Dec 12, 2006 7:53 am

I have asked for it for the last ages and it never gets added, even tho is a noddy change (ditto for jumping to a given item in a category) :)

I auto set play times on each track as they are played (and a few other tings...), Anyway, heres a bit of noddy c# code to do it -


//A Timer used to check the playstate
private System.Timers.Timer m_Timer = null;

//The last played song
private string m_LastPlayedFileName = "";



/// <summary>
/// Start the timer
/// </summary>
private void StartTimer(double Delay)
{
m_Timer = new System.Timers.Timer();
m_Timer.Enabled = false;
m_Timer.Interval = Delay;
m_Timer.Elapsed += new ElapsedEventHandler(OnTimer);
m_Timer.Enabled = true;
}


/// <summary>
/// This is called by the timer
/// </summary>
private void OnTimer(object source, ElapsedEventArgs e)
{
if (m_Timer != null)
CheckPlayer();
}//OnTimer


/// <summary>
/// Current song is...
/// </summary>
private string GetPlayingSong()
{
string Str = m_Helper.ConvertVariables("audioplayer>now>%parameter%");

if (Str == null)
Str = "";

return Str;
}//GetPlayingSong


/// <summary>
/// Elasped time is?
/// </summary>
private string GetPlayTime()
{
string Str = m_Helper.ConvertVariables("audioplayer>time>%elapsed%");

if (Str == null)
Str = "";

return Str;
}//GetPlayTime


/// <summary>
/// Look for song changes
/// </summary>
private void CheckPlayer()
{
string FileName = GetPlayingSong();

//HAS ANYTHING CHANGED
if (FileName != "" )
{
if ( FileName != m_LastPlayedFileName)
{
//IT SOMETIMES RETURNS SHIT RESULTS SO DOUBLE CHECK IT...
if (GetPlayingSong() != m_LastPlayedFileName)
{
//AND AGAIN
if (GetPlayingSong() != m_LastPlayedFileName)
{
string Elapsed = GetPlayTime();

//WAIT A FEW SECS BEFORE SETTING THE PLAYEDTIME
if (Elapsed != "" && Elapsed != "0:00" )
{
m_LastPlayedFileName = FileName;
m_Helper.SendCommand("command:xlobby:runevent:group:name")
}
}
}
}
}
}//CheckPlayer

S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England

Postby P3rv3rt B3ar on Thu Dec 21, 2006 9:06 pm

I just implemented so that new xPerT updates MSN messenger music tag automaticly based on nowplaying variable. If theres interest about this feature, just ask and i put new version available. I didnt made this event firing capability however, since pittaway has it covered up there and i personally dont atleast yet have need for it, but im replying here cause what i did is ofcourse very similar, keep watching changes in nowplaying and i agree with Pittaways observation of returned shit... and i have to elaborate on that.

What i got out again was mostly shit. I have encountered this problem before and have concluded that it is because of concurrent calls to ConvertVariables(). Unfortunately ConvertVariables() is implemented so that it cannot handle several calls simultaneously. So only option for plugin writer is to police calls going in by himself. Because of cat features xPerT forexample is bombarding this function with calls constantly, so i have noticed that simple locking of function wont do, it would simply slow down everything way too much. I have to use much higher level scheme to share time of this function between different threads within xPerT.

All that doesnt really worry me, we can police our own plugins, even with complex schemes, now that we are all aware of the culprit. What worries me is if this behavior can happen between plugins, for example plugin A query is answered to plugin B just because plugin B had nerve to ask question while A was waiting his answer. If that is indeed the case, we r really having some problems, any observation anybody?
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Postby S Pittaway on Fri Dec 22, 2006 11:47 am

all i know that convertvariabe is not 100% accurate... :)



I wrote a plugin to fire an event on track changes. It also updates a lastplayed field on the track changes and you can set a ratiings (*,**, ***, ****, *****) for the current track.

The lastplayed time/rating are used in a "smart shuffle" which i wrote to actually randomise the playlist so i can scroll around it as normal when shuffle is on, the shuffle function factors in the rating and the lastplayed time so you are more likely to here all of your songs... I asked for it a few times and got bored and wrote it myself...

It also adds a few milkdrop functions (i use milkdrop alot on my skin) so it gives you on/off, next/prev/random vis, ratings etc

While at it i added a few more feilds to the music database (it has a command to update the database) it sticks in artist.sort, albumname.sort (changes the group/the album to group, the/album,the) and i added a (track) album.artist tag so i can quickly find entries when jumping to selection screens.

If it sounds usefull to anyone let me know, and i could see if someone could host it?
S Pittaway
 
Posts: 651
Joined: Wed Jan 25, 2006 11:08 am
Location: Manchester, England

Postby dalanik on Fri Dec 22, 2006 11:51 am

Sounds cool! :-)
dalanik
 
Posts: 885
Joined: Mon Apr 19, 2004 12:35 pm
Location: Prague, Czech Republic