Windows Phone How to listen to volume/muisc control events

限于喜欢 提交于 2019-12-12 22:49:42

问题


Is it possible to listen to system's volume and music control events (Next/Prev)? I am playing a song from MediaLibrary using MediaPlayer but how to capture Next\Prev button press event? Thanks!


回答1:


Volume Events

It's not possible to listen for (or subscribe to) the system volume events. You cannot find out the current system volume or know when the volume keys on the phone are pressed.

If your app is playing music using a MediaElement, for example, you simply play the sounds or music blindly not knowing what the system volume is.

Developers have voted to improve this API which will hopefully happen in a future release.


Music Events

If your app is playing music using the BackgroundAudioPlayer, you can subscribe to the PlayStateChanged event. You can detect if music is playing using the MediaPlayer class. Although this is an XNA library, it works in WP7 and WP8.

If the user starts music in your app, it will stop whatever music the system is playing and take over. The opposite is also true. If your app is playing music, and the user goes to another music app, your BackgroundAudioPlayer will receive PlayState.Stopped.



来源:https://stackoverflow.com/questions/18036057/windows-phone-how-to-listen-to-volume-muisc-control-events

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