INTERACT FORUM
Windows => Plug-in Development => Topic started by: teodorom on July 03, 2017, 02:09:15 pm
-
Hi,
I'm trying to tame (and control) the state machine of MC, and I don't understand the events sequence.
When I load a .MPL into the "Playing Now" section, and I press "play" I get
08:51:34.206 MCC: NOTIFY_PLAYLIST_FILES_CHANGED PLAYSTATE_WAITING 1
08:51:34.407 MCC: NOTIFY_TRACK_CHANGE PLAYSTATE_WAITING 1 Sgt. Pepper's Lonely Hearts Club Band (Remix)
08:51:34.422 MCC: NOTIFY_PLAYERSTATE_CHANGE PLAYSTATE_WAITING 1 Sgt. Pepper's Lonely Hearts Club Band (Remix)
08:51:34.458 MCC: NOTIFY_TRACK_CHANGE PLAYSTATE_WAITING 1 Sgt. Pepper's Lonely Hearts Club Band (Remix)
08:51:34.775 MCC: NOTIFY_PLAYERSTATE_CHANGE PLAYSTATE_PLAYING 1 Sgt. Pepper's Lonely Hearts Club Band (Remix)
08:52:23.423 MCC: NOTIFY_PLAYERSTATE_CHANGE PLAYSTATE_WAITING 1 Sgt. Pepper's Lonely Hearts Club Band (Remix)
I then let the music flow so the next track is played automatically (and gapless):
08:52:23.553 MCC: NOTIFY_PLAYERSTATE_CHANGE PLAYSTATE_PLAYING 2 With A Little Help From My Friends (Remix)
08:52:23.723 MCC: NOTIFY_PLAYERSTATE_CHANGE PLAYSTATE_WAITING 2 With A Little Help From My Friends (Remix)
08:52:23.860 MCC: NOTIFY_PLAYERSTATE_CHANGE PLAYSTATE_PLAYING 2 With A Little Help From My Friends (Remix)
08:52:32.348 MCC: NOTIFY_TRACK_CHANGE PLAYSTATE_PLAYING 2 With A Little Help From My Friends (Remix)
Then I press the "Next" button:
08:52:46.522 MCC: NOTIFY_PLAYERSTATE_CHANGE PLAYSTATE_WAITING 3 Lucy In The Sky With Diamonds (Remix)
08:52:46.573 MCC: NOTIFY_TRACK_CHANGE PLAYSTATE_PLAYING 3 Lucy In The Sky With Diamonds (Remix)
08:52:46.609 MCC: NOTIFY_PLAYERSTATE_CHANGE PLAYSTATE_PLAYING 3 Lucy In The Sky With Diamonds (Remix)
08:52:46.788 MCC: NOTIFY_PLAYERSTATE_CHANGE PLAYSTATE_WAITING 3 Lucy In The Sky With Diamonds (Remix)
08:52:46.809 MCC: NOTIFY_PLAYERSTATE_CHANGE PLAYSTATE_PLAYING 3 Lucy In The Sky With Diamonds (Remix)
What I want to know is when
- a track is waiting to be played
- a track starts playing
The event sequence is very confusing: is there any other "State" I can check in order to eliminate that ambiguity ?
Thanks
-
Just in case, the relevant (yes, I know, to get the above output the code could be much simpler, but this is the fragment I shall try to use to get what I want) piece of code is:
private void MJEvent(String s1, String s2, String s3)
{
MediaCenter.IMJCurPlaylistAutomation curPlaylist = mcRef.GetCurPlaylist();
MediaCenter.IMJPlaybackAutomation playback = mcRef.GetPlayback();
switch (s1)
{
case "MJEvent type: MCCommand":
switch (s2)
{
case "MCC: NOTIFY_TRACK_CHANGE":
Debug.WriteLine(DateTime.Now.ToString("hh:mm:ss.fff") + " MCC: NOTIFY_TRACK_CHANGE " + playback.State.ToString() +
" " + curPlaylist.GetFile(curPlaylist.Position).Tracknumber +
" " + curPlaylist.GetFile(curPlaylist.Position).Name);
break;
case "MCC: NOTIFY_PLAYERSTATE_CHANGE":
if ("PLAYSTATE_WAITING" == playback.State.ToString())
{
Debug.WriteLine(DateTime.Now.ToString("hh:mm:ss.fff") + " MCC: NOTIFY_PLAYERSTATE_CHANGE " + playback.State.ToString() +
" " + curPlaylist.GetFile(curPlaylist.Position).Tracknumber +
" " + curPlaylist.GetFile(curPlaylist.Position).Name);
}
if ("PLAYSTATE_PLAYING" == playback.State.ToString())
{
Debug.WriteLine(DateTime.Now.ToString("hh:mm:ss.fff") + " MCC: NOTIFY_PLAYERSTATE_CHANGE " + playback.State.ToString() +
" " + curPlaylist.GetFile(curPlaylist.Position).Tracknumber +
" " + curPlaylist.GetFile(curPlaylist.Position).Name);
}
break;
default:
// Unknown (new?) event
break;
}
break;
default:
// Unknown (new?) type
break;
}
-
First off i'm not going to be that much help. I have dabbled in plugins for MC a bit, but using VB.
Are you using the FireMJEvent to call your function?
From the WIKI:
Public Sub MC_FireMJEvent(ByVal s0 As String, ByVal s1 As String, ByVal s2 As String) Handles MC.FireMJEvent
_RelayEvent = New RelayEvent(AddressOf MyRelayEvent)
BeginInvoke(_RelayEvent, s0, s1, s2)
End Sub
I've used the fire event to trigger a query on various tags on an event like track change and playstate
Ken.
-
Thanks,
but I think we are doing the same thing.
In order to register the event handler I use the following code:
public void Init(MediaCenter.MCAutomation mcRef)
{
try
{
this.mcRef = mcRef;
// This tells MC to also call our MJEvent method
this.mcRef.FireMJEvent += new MediaCenter.IMJAutomationEvents_FireMJEventEventHandler(MJEvent);
}
catch (Exception e)
{
errorHandler(e);
}
}
This way I catch the MC events.
My problem is that I catch too many events.
If you look at the sequences I have posted you see that the same event is fired more that one time.
What I need is the ability to react
- to a WAITING event by loading the address of the stream, and
- to a PLAYING event by deleting the address of the stream (once the play is started it's no more needed).
As I said this is to make piracy more difficult (the address of the stream will be visible only for a few seconds and only for the track that will be played).