ios - AVAudioSession 无法在 iOS 7 上播放

标签 ios avaudioplayer

在 iOS 6 上,我已经能够设置一个 AVAudioSession 来播放 mp3 文件。在 iOS 7 上使用 Base set 运行时,这不再有效。任何想法为什么这行不通?该应用程序永远不会崩溃...它只是不播放 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];   
}

最佳答案

尝试使用

NSURL *newURL = [NSURL fileURLWithPath:_entry.articleUrl];

代替

NSURL *newURL = [NSURL URLWithString:_entry.articleUrl];

关于ios - AVAudioSession 无法在 iOS 7 上播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18765265/

相关文章:

ios - ObjC - 如何明确地将所有权移交给将异步执行的 block ?

ios - 图像中带有复选框的 UICollectionView Cell

swift 2 : AVAudioPlayers to play multiple sounds at once

ios - 无法通过 AVAudioPlayer 中的 URL 播放声音

swift - 无法在 ios13 swift 以上播放本地 mp3

ios - 从 iOS 中的控制中心控制应用程序

c# - 使用 c#.net 将立体声作为单声道播放不同 channel 的声音

ios - 动态 CSS 未在 iOS 中加载

ios - 调用错误中的额外参数 - Swift

ios - ZBAR读取静态UIImage(无相机预览)