MediaPlayerLauncher on WP7 - how to resume previously playing media?

梦想与她 提交于 2019-12-07 01:52:23

问题


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?


回答1:


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;



回答2:


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!



来源:https://stackoverflow.com/questions/11864557/mediaplayerlauncher-on-wp7-how-to-resume-previously-playing-media

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!