void GetPlayerInfo() { MediaAppState currentState = MediaAppState.NotRunning; if(iTunesConnector.isRunning() == 0) currentState = iTunesConnector.retrieveState(); if(currentState != state){ state = currentState; DispatchStateChange(state); } switch(state){ case MediaAppState.NotRunning: case MediaAppState.Stopped: break; default: Song currentSong = new Song(); currentSong.title = iTunesConnector.retrieveTrackName(); currentSong.album = iTunesConnector.retrieveAlbumName(); currentSong.artist = iTunesConnector.retrieveArtistName(); if(currentSong != song){ song = currentSong; DispatchSongChange(song); } break; } }
/* * MUSIC PLAYER EVENTS */ void OnMediaAppStateChanged(MediaAppState state) { switch(state){ /* * if the media player has finished its playlist or has suddenly closed, then * handle by dispatching the correct events to the other components. */ case MediaAppState.NotRunning: case MediaAppState.Stopped: if(isRecording) OnStopRecordClicked(); if(isPlaying) OnStopPlayClicked(); break; default: break; } }
/* * MEDIA PLAYER EVENTS */ void OnMediaAppStateChanged(MediaAppState newState) { state = newState; }
/** * Convenience method to dispatch a State Change event */ private void DispatchStateChange(MediaAppState newState) { SendMessage("OnMediaAppStateChanged", newState, SendMessageOptions.DontRequireReceiver); }