gpt4 book ai didi

iPhone:如何检测 iTunes 是否正在播放?

转载 作者:行者123 更新时间:2023-12-03 18:39:10 25 4
gpt4 key购买 nike

我注意到一些应用程序在启动时以编程方式将 iTunes(如果其正在运行)静音。这是如何实现的?我有一个带有背景音乐的游戏,并且想要停止 iTunes 或至少收到一条表明 iTunes 正在播放的消息,以便我可以停止游戏的背景音乐。

谢谢,马克。

最佳答案

你不需要。通过 Audio Session ,您可以决定音频的行为方式。

来自Audio Session Programming Guide :

With the audio session interface, you specify aspects of your application’s audio behavior and configure it to live harmoniously within the iPhone audio environment. You start by asking yourself questions such as these:

  • Do you want your audio to be silenced by the Ring/Silent switch? The answer is probably “yes” if audio is not essential to using your application successfully. (Users will appreciate being able to run your game in a meeting with no one the wiser.)

  • Do you want iPod audio to continue playing when your audio starts? This could be appropriate for a virtual piano, letting users play along to songs in their libraries. You’d want iPod audio to stop, however, for a streaming radio application.

您可能想要这个:

UInt32 sessionCategory = kAudioSessionCategory_SoloAmbientSound;
AudioSessionSetProperty (
kAudioSessionProperty_AudioCategory,
sizeof (sessionCategory),
&sessionCategory
);

有关更多行为类型,请查看 Audio Session Categories ,或阅读整个 Audio Session Programming Guide .

关于iPhone:如何检测 iTunes 是否正在播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/925029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com