Windows Phone如何收听音量/音乐控制事件 [英] Windows Phone How to listen to volume/muisc control events

查看:139
本文介绍了Windows Phone如何收听音量/音乐控制事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以收听系统的音量和音乐控制事件(下一个/上一个)?我正在使用MediaPlayer播放MediaLibrary中的歌曲,但是如何捕获Next \ Prev按钮按下事件?谢谢!

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!

推荐答案

批量事件

不可能监听(或订阅)系统音量事件.您无法找出当前的系统音量,也无法知道何时按下手机上的音量键.

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.

例如,如果您的应用程序正在使用MediaElement播放音乐,则您只是盲目地播放声音或音乐,而不知道系统音量是多少.

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.

开发人员具有投票以改进此API ,希望会在将来的版本中实现.

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


音乐事件

如果您的应用正在使用 BackgroundAudioPlayer ,您可以订阅检测音乐是否在播放.尽管这是XNA库,但它可在WP7和WP8中使用.

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.

如果用户在您的应用中启动音乐,它将停止系统正在播放的任何音乐并接管.反之亦然.如果您的应用正在播放音乐,并且用户转到另一个音乐应用,则您的BackgroundAudioPlayer将收到PlayState.Stopped.

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.

这篇关于Windows Phone如何收听音量/音乐控制事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆