Allowing suspension of a windows store app when audio is paused

久未见 提交于 2019-12-23 02:42:09

问题


One of the requirements for windows store apps is that they support suspending. My app is marked as a background audio task, so it doesn't suspend when left alone, but it is supposed to suspend when the audio is paused.

I can't find out how to "tell Windows" when it can or can't suspend. How do I have my background audio application pass the package validation?


回答1:


To enable background audio you must register handlers for the Media Control button events. These are in the Windows.Media.MediaControl class, specifically the PlayPressed, PausePressed, PlayPausePressed (some hardware has a single button for both), and StopPressed. If you don't have handlers for these, then background audio won't work. With the handlers, Windows will know when the audio is paused, and will then be able to suspend you. Fortunately, by virtue of your Play[Pause]Pressed handlers, Windows will also resume the app when playback starts again.

These events work for both hardware and on-screen buttons, e.g.

If you have multiple tracks you are playing, then registering handlers for NextTrackPressed and PrevTrackPressed controls whether the forward/back buttons are enabled here. The AlbumArt, TrackName, and ArtistName fields in the MediaControl class are also used to set the data in the medial control UI above.




回答2:


I was working on a Windows Store app recently (online radio app) with the same Background Audio Task support, and kept failing the WACK - it turns out that you can't have your MediaElement for the background audio be set to AutoPlay = true, or you will constantly fail the suspend test.

This (and some other tips) in this handy yet not publicised enough list of tips: http://www.slideshare.net/msdnbelux/windows-store-top-learnings-from-the-first-belgian-windows-8-apps



来源:https://stackoverflow.com/questions/12907731/allowing-suspension-of-a-windows-store-app-when-audio-is-paused

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