如何检测是否有其他应用程式正在播放背景音乐? [英] How do I detect if other apps are playing background audio?

查看:312
本文介绍了如何检测是否有其他应用程式正在播放背景音乐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone / iPad的游戏,并且不希望我的背景音乐与音乐的用户可能已经被打造成干扰。

I am making a game for iphone/ipad, and don't want my background music to interfere with music the user might already be playing.

我知道我可以使用MPPlayerController获得iPod应用程序的状态,但如何将我的应用程序计算出,如果别的东西,像潘多拉,打得背景音乐上的iOS4?

I know I can get the state of the iPod app using MPPlayerController, but how would my app figure out if something else, like Pandora, was playing background audio on iOS4?

推荐答案

我终于想通了这一点。我见过很多例子,但不能永远让他们的工作。

I finally figured this out. I had seen plenty of examples, but couldn't ever get them to work.

大多数例子在那里不指出,对于类似:

Most of the examples out there don't point out that for something like:

    UInt32   propertySize, audioIsAlreadyPlaying;

propertySize = sizeof(UInt32);
AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &propertySize, &audioIsAlreadyPlaying);

工作,适当的框架添加到您的应用程序是AudioToolbox。我一直试图增加其他音频框架,并始终无缘的那一个。

to work, the proper framework to add to you app is AudioToolbox. I kept trying to add other audio frameworks and always missed that one.

一旦你添加一个工作框架(和它导入到有问题的code文件)只是测试,看看是否audioIsAlreadyPlaying是0或1。

Once you add that frame work (and import it into the code file in question) just test to see if audioIsAlreadyPlaying is zero or one.

这篇关于如何检测是否有其他应用程式正在播放背景音乐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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