应用AVPlayer播放后播放mp4中断iPod音乐 [英] App with AVPlayer plays mp4 interrupt iPod music after launched

查看:816
本文介绍了应用AVPlayer播放后播放mp4中断iPod音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用AVPlayer播放mp4,当我的应用程序完成启动时,它会中断iPod音乐,虽然我已将音频会话设置为允许与其他人混音

My App plays mp4 using AVPlayer, when my application finish launching, it interrupt the iPod music, although I have set the audio session to allow mix with others in

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    AudioSessionInitialize(NULL, NULL, NULL, NULL);
    AudioSessionSetActive(true);
    UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
    UInt32 allowMixWithOthers = true;
    AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixWithOthers), &allowMixWithOthers);

视频控制器确实出现后,我重新启动iPod音乐,它可以正常使用我的应用程序而不会中断我的应用程序不会再打断音乐了。

After view controller did appear, I restart the iPod music, it works fine with my app without interruption and my app won't interrupt the music anymore.

有谁知道问题是否可以解决?我还检查了 myapp-info.plist ,找不到属性以防止中断iPod。

Does anyone know whether the problem can be solved or not? I also checked the myapp-info.plist, find no property to prevent interrupting iPod.

所有AudioSession方法返回没有错误。

All the AudioSession Methods return no error.

这里是iPhoneConfigureUtility中的日志:

here are the logs in iPhoneConfigureUtility:

Aug 20 10:55:54 nova-teki-iPhone audiotest[3510] <Warning>: AudioSessionInitialize status = 0
Aug 20 10:55:55 nova-teki-iPhone kernel[0] <Debug>: ALS: kIOHIDDisplayBrightnessSliderPositionKey=69% (0xb226)
Aug 20 10:55:55 nova-teki-iPhone audiotest[3510] <Warning>: AudioSessionSetActive status = 0
Aug 20 10:55:55 nova-teki-iPhone audiotest[3510] <Warning>: kAudioSessionProperty_AudioCategory status = 0
Aug 20 10:55:55 nova-teki-iPhone audiotest[3510] <Warning>: kAudioSessionProperty_OverrideCategoryMixWithOthers status = 0
Aug 20 10:55:56 nova-teki-iPhone audiotest[3510] <Error>: [10:55:56.005] FigSubtitleSampleCreateFromPropertyList signalled err=50 (kFigCFBadPropertyListErr) (NULL or bad plist) at /SourceCache/EmbeddedCoreMedia/EmbeddedCoreMedia-1033.6/BuildSystem/XcodeProjects/MediaToolbox/../../../Sources/../Prototypes/ClosedCaptions/FigCaptionCommand.c line 762
Aug 20 10:55:56 nova-teki-iPhone audiotest[3510] <Warning>: Application windows are expected to have a root view controller at the end of application launch

以下是我的测试程序:

OSStatus status = AudioSessionInitialize(NULL, NULL, NULL, NULL);
status = AudioSessionSetActive(true);
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
status = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
UInt32 allowMixWithOthers = true;
status = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixWithOthers), &allowMixWithOthers);

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(itemDidPlayToEndTime:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:nil];

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
playerView = [[MoviePlayerView alloc] initWithFrame:self.window.bounds];
AVPlayer *player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sunny" ofType:@"mp4"]]];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[player play];
[(AVPlayerLayer *)playerView.layer setPlayer:player];
[self.window addSubview:playerView];
[playerView release];

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;


推荐答案

最后,我弄清楚出了什么问题。

Finally, I figure out what's wrong.

AudioSessionInitialize(NULL, NULL, NULL, NULL);  
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
UInt32 allowMixWithOthers = true;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixWithOthers), &allowMixWithOthers);
AudioSessionSetActive(true);

必须在AudioSessionSetProperty之后调用AudioSessionSetActive,它现在可以正常工作。

AudioSessionSetActive must be called after AudioSessionSetProperty, it works fine now.

这篇关于应用AVPlayer播放后播放mp4中断iPod音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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