/// <summary> /// Fires when a message is recieved from the foreground app /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e) { foreach (var one in e.Data) { string key = one.Key; switch (key.ToLower()) { case Constants.AppSuspended: Debug.WriteLine("App suspending"); // App is suspended, you can save your task state at this point foregroundAppState = ForegroundAppStatus.Suspended; ApplicationSettingsHelper.SaveSettingsValue(Constants.CurrentTrack, Playlist.CurrentTrackName); break; case Constants.AppResumed: Debug.WriteLine("App resuming"); // App is resumed, now subscribe to message channel foregroundAppState = ForegroundAppStatus.Active; break; case Constants.Trackat: // User has chosen to skip track from app context. foregroundAppState = ForegroundAppStatus.Active; Debug.WriteLine("play to Trackat"); Trackat(one.Value.ToString()); break; case Constants.StartPlayback: //Foreground App process has signalled that it is ready for playback foregroundAppState = ForegroundAppStatus.Active; Debug.WriteLine("Starting Playback"); StartPlayback(); break; case Constants.SkipNext: // User has chosen to skip track from app context. foregroundAppState = ForegroundAppStatus.Active; Debug.WriteLine("Skipping to next"); SkipToNext(); break; case Constants.SkipPrevious: // User has chosen to skip track from app context. foregroundAppState = ForegroundAppStatus.Active; Debug.WriteLine("Skipping to previous"); SkipToPrevious(); break; case Constants.conCurrentFile: Debug.WriteLine("Play current File"); object value = string.Empty; bool rev = e.Data.TryGetValue(Constants.conCurrentFile, out value); if (rev) { string fileToken = value.ToString(); StartFile(fileToken); } break; case Constants.conPlaySingleFile: object v = string.Empty; bool bl = e.Data.TryGetValue(Constants.conPlaySingleFile, out v); if (bl) { string fileToken = v.ToString(); StartSingleFile(fileToken); } break; case Constants.conPlayByIndex: object vByindex = string.Empty; bool bplay = e.Data.TryGetValue(Constants.conPlayByIndex, out vByindex); if (bplay) { int index = Convert.ToInt32(vByindex); StartPlayback(index); } break; } } }