AVAudioSession 无法在 iOS 7 上播放
Posted
技术标签:
【中文标题】AVAudioSession 无法在 iOS 7 上播放【英文标题】:AVAudioSession Won't Play On iOS 7 【发布时间】:2013-09-12 13:09:59 【问题描述】:在 ios 6 上,我已经能够设置一个 AVAudioSession 来播放 mp3 文件。在 iOS 7 中使用 Base 设置运行时,这不再有效。任何想法为什么这不起作用?该应用程序永远不会崩溃......它只是不播放 mp3。我已经验证了相同的代码和相同的 URL 可以在 iOS 6 应用程序上运行。
错误是:
ERROR: 185: Error creating aggregate audio device: 'what'
WARNING: 219: The input device is 0x31; 'AppleHDAEngineInput:1B,0,1,0:1'
WARNING: 223: The output device is 0x28; 'AppleHDAEngineOutput:1B,0,1,1:0'
ERROR: 398: error 'what'
_itemFailedToPlayToEnd:
kind = 1;
new = 2;
old = 0;
代码:
- (void)viewDidLoad
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (setCategoryError) /* handle the error condition */
NSError *activationError = nil;
[audioSession setActive:YES error:&activationError];
if (activationError) /* handle the error condition */
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
NSURL *newURL = [NSURL URLWithString:_entry.articleUrl];
self.player = [[MPMoviePlayerController alloc] initWithContentURL: newURL];
[player prepareToPlay];
player.allowsAirPlay = YES;
player.scalingMode = MPMovieScalingModeAspectFit;
player.view.frame = self.view.frame;
[self.view addSubview: player.view];
[self.player setFullscreen:YES animated:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(exitedFullscreen:)
name:MPMoviePlayerDidExitFullscreenNotification
object:player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackStateChanged:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:player];
[player play];
[super viewDidLoad];
【问题讨论】:
为set Active添加日志语句:NSError *activationError = nil; if ([audioSession setActive:YES error:&activationError] ) NSLog(@"Audiosession errore: %@", error)
@rckoenes 我刚刚在原始帖子中添加了错误和警告消息日志。
类似问题:***.com/questions/19104728/… 和 ***.com/questions/19088955/…。你的文件名有空格吗?
【参考方案1】:
尝试使用
NSURL *newURL = [NSURL fileURLWithPath:_entry.articleUrl];
而不是
NSURL *newURL = [NSURL URLWithString:_entry.articleUrl];
【讨论】:
以上是关于AVAudioSession 无法在 iOS 7 上播放的主要内容,如果未能解决你的问题,请参考以下文章
如何解决 iOS 中的 AVCaptureSession v AVAudioSession 冲突?