允许Windows应用商店的应用程序暂停时,音频暂停

问题描述:

一个为Windows Store应用程序的要求是,他们支持悬浮。我的应用程序被标记为背景音乐的任务,所以单独留在家中时,它不会停止,但它应该是暂停时,音频暂停。

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.

我不能找出如何告诉Windows时,它可以或不能暂停。我怎么有我的后台音频应用程序通过包验证?

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?

要启用后台音频,你必须注册媒体控制按钮事件处理程序。这些都是在Windows.Media.MediaControl类,特别是玩pressed,暂停pressed,PlayPause pressed(一些硬件有两个一个按钮),并停止pressed。如果您没有为这些处理,然后背景音乐将无法正常工作。随着处理程序时,Windows会知道什么时候该音频暂停,然后就可以暂停你。幸运的是,凭借您的播放[暂停] pressed处理程序时,Windows也将恢复应用程序时重新开始播放。

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.

如果你有在玩多轨道,为​​NextTrack $ P $然后注册处理pssed和prevTrack pressed控制是否前进/后退按键集中在这里启用。的AlbumArt,TRACKNAME和ARTISTNAME在MediaControl类字段也被用于上述的内侧控制UI设置数据

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.