检查 iPod 音乐播放是否有问题
我想检查 ipod 音乐是否播放,所以我添加了媒体播放器框架并导入它:
#import <MediaPlayer/MediaPlayer.h>
然后我进入了 NSCoder:
-(id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if(self)
{
if ([[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying) {
}
else {
[self playBgMusic];
} }
return self; }
但这不起作用。如果 ipod 音乐正在播放并且我启动应用程序,ipod 音乐将关闭并播放应用程序中的音乐。
怎么了?
i want to check if ipod music is played, so i added the mediaplayer framework and imported it:
#import <MediaPlayer/MediaPlayer.h>
then i've got in an NSCoder:
-(id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if(self)
{
if ([[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying) {
}
else {
[self playBgMusic];
} }
return self; }
But this doesn't work. If ipod music is playing and I start the app the ipod music turns off and the music from the app is played.
What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其导入您的应用程序委托中。
将此代码放入您的 application:didFinishLaunchingWithOptions: 方法中,以便它在应用程序启动时运行。
这将设置您的应用程序用于允许与 iPod 音乐播放器混合的音频会话的“类别”。默认情况下,类别设置为“AVAudioSessionCategorySoloAmbient”,不允许混合。请参阅下面的 Apple 文档。
处理电影和 iPod 音乐
AVAudioSession 类参考
Import it into your app delegate.
Put this code in your application:didFinishLaunchingWithOptions: method so it gets run on app launch.
This sets the "category" of the audio session your app uses to allow mixing with the iPod music player. By default the category is set to "AVAudioSessionCategorySoloAmbient" which does not allow mixing. See Apple's doc below.
Working with Movies and iPod Music
AVAudioSession Class Reference