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
Bill Lott wrote:This would be helpful. Anyone know how 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