/// <summary> /// Fire event to diable button states temporary, will be activated after command has done something /// </summary> /// <param name="doEvent"></param> /// <param name="sender"></param> private void DoEvent_MP_OnControleButtonStateChange_DisableTemporary(MP_OnControleButtonStateChange doEvent, object sender) { // Disable all button states (will be recalculated when normal event // is fired previousButton = MPButtonState.Inactive; stopButton = MPButtonState.Inactive; playButton = MPButtonState.Inactive; pauseButton = MPButtonState.Inactive; nextButton = MPButtonState.Inactive; if (doEvent != null) { MP_Params param = new MP_Params(); param.Params = new object[] { doEvent, sender, MPButtonState.Inactive, MPButtonState.Inactive, MPButtonState.Inactive, MPButtonState.Inactive, MPButtonState.Inactive }; SynchronizationContext sc; lock (lockVAR) { sc = synchronizationContext; } //lock if (sc != null) { sc.Post(HandleOnEventCallUserCode, param); } else { HandleOnEventCallUserCode(param); } } }
private void MP_OnControleButtonStateChange(object sender, MPButtonState previousButton, MPButtonState stopButton, MPButtonState playButton, MPButtonState pauseButton, MPButtonState nextButton) { bPrevious.Enabled = (previousButton == MPButtonState.Active); bNext.Enabled = (nextButton == MPButtonState.Active); bTogglePlay.Enabled = (stopButton == MPButtonState.Active || playButton == MPButtonState.Active || pauseButton == MPButtonState.Active); }
private void DoEvent_MP_OnControleButtonStateChange(MP_OnControleButtonStateChange doEvent, object sender, bool forceEvent = false) { MPButtonState oldPreviousButton = previousButton; MPButtonState oldStopButton = stopButton; MPButtonState oldPlayButton = playButton; MPButtonState oldPauseButton = pauseButton; MPButtonState oldnextButton = nextButton; // Determine the buttonstates lock (lockVAR) { if (netConnection == null || !netConnection.IsConnected || currentPlaylist.Count <= 0 || commandInProgress) { // we're not connected to a server, of nothing to play previousButton = MPButtonState.Inactive; stopButton = MPButtonState.Inactive; playButton = MPButtonState.Inactive; pauseButton = MPButtonState.Inactive; nextButton = MPButtonState.Inactive; } else if (netStreams.Count == 0) { // we're connected to server, but not playing previousButton = MPButtonState.Inactive; stopButton = MPButtonState.Inactive; playButton = MPButtonState.Active; pauseButton = MPButtonState.Inactive; nextButton = MPButtonState.Inactive; } else if (netStreams.Count > 0) { // we're playing music of somekind previousButton = MPButtonState.Inactive; // previous is also active after 10 seconds have played if (currentPlaylist.PreviousMediaItemIndex != -1 || Position > PREVIOUS_CMD_IS_GOTOBEGIN_IN_SEC) { previousButton = MPButtonState.Active; } nextButton = MPButtonState.Inactive; if (currentPlaylist.NextMediaItemIndex != -1) { nextButton = MPButtonState.Active; } switch (netStreams[0].PlayState) { case NetStreamState.None: // ????????? stopButton = MPButtonState.Inactive; playButton = MPButtonState.Inactive; pauseButton = MPButtonState.Inactive; previousButton = MPButtonState.Inactive; nextButton = MPButtonState.Inactive; break; case NetStreamState.Connecting: stopButton = MPButtonState.Inactive; playButton = MPButtonState.Inactive; pauseButton = MPButtonState.Inactive; previousButton = MPButtonState.Inactive; nextButton = MPButtonState.Inactive; break; case NetStreamState.Playing: stopButton = MPButtonState.Active; playButton = MPButtonState.Inactive; pauseButton = MPButtonState.Active; break; case NetStreamState.Seek: stopButton = MPButtonState.Inactive; playButton = MPButtonState.Inactive; pauseButton = MPButtonState.Inactive; previousButton = MPButtonState.Inactive; nextButton = MPButtonState.Inactive; break; case NetStreamState.Pause: stopButton = MPButtonState.Active; playButton = MPButtonState.Active; pauseButton = MPButtonState.Inactive; break; } //switch } } //lock /* Console.WriteLine("--"); Console.WriteLine("previous:" + previousButton.ToString()); Console.WriteLine("stop:" + stopButton.ToString()); Console.WriteLine("play:" + playButton.ToString()); Console.WriteLine("pause:" + pauseButton.ToString()); Console.WriteLine("next:" + nextButton.ToString()); */ // when state of one or more buttons is changed fire an event! if (forceEvent || oldPreviousButton != previousButton || oldStopButton != stopButton || oldPlayButton != playButton || oldPauseButton != pauseButton || oldnextButton != nextButton) { if (doEvent != null) { MP_Params param = new MP_Params(); param.Params = new object[] { doEvent, sender, previousButton, stopButton, playButton, pauseButton, nextButton }; SynchronizationContext sc; lock (lockVAR) { sc = synchronizationContext; } //lock if (sc != null) { sc.Post(HandleOnEventCallUserCode, param); } else { HandleOnEventCallUserCode(param); } } } }