MediaPlayerLauncher on WP7 - how to resume previou

2019-04-28 08:17发布

I'm using a MediaPlayerLauncher to show movietrailers in my WP7 application, like this:

MediaPlayerLauncher mpl = new MediaPlayerLauncher();
mpl.Media = new Uri(trailerUrl, UriKind.Absolute);
mpl.Controls = MediaPlaybackControls.All;
mpl.Show();

This works just fine, except one thing: if the user is already listening to music in the background, and launch a trailer, the music is not resumed after the trailer is done playing (or if the user closes the video).

Does anyone know how i can resume the previously playing music/media, if even possible?

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-04-28 08:34

Local media playing through XNA or a 'background audio agent'?

When you play media in WP7 / WP8, the OS audio context is taken, and the original context is lost. If the audio was launched from an external application, then you cannot resume at all. If the previous media was launched from within your application, then you could store the meta-data and re-play once your trailer is finished. The media would, of course, then begin playing from the start, rather than where the user left off. Unfortunately XNA does not allow you to seek within a given piece of media; however you can seek within an 'audio agent' instance of 'BackgroundAudioPlayer' by setting player.Position. It's also worth looking at the MediaHistory API:

var nowPlaying = Microsoft.Devices.MediaHistory.Instance.NowPlaying;
查看更多
啃猪蹄的小仙女
3楼-- · 2019-04-28 08:50

Figured it out. Calling MediaPlayer.Resume() right after show() solves the issue:

mpl.Media = new Uri(trailerurl, UriKind.Absolute);
mpl.Controls = MediaPlaybackControls.All;
mpl.Show();

MediaPlayer.Resume();

However, i would still like to know how to resume radio and spotify!

查看更多
登录 后发表回答