2013-09-12 3 views
7

На iOS 6 я смог настроить AVAudioSession для воспроизведения mp3-файлов. Во время работы с базой, установленной в iOS 7, это больше не работает. Любые идеи, почему это не сработает? Приложение никогда не сбой ... он просто не воспроизводит mp3. Я проверил этот же код и тот же URL-адрес работает в приложениях iOS 6.AVAudioSession не будет воспроизводиться на iOS 7

Ошибки:

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]; 
} 
+0

Добавить журнал statement для set Active: 'NSError * activationError = nil; if ([audioSession setActive: YES error: & activationError]) {NSLog (@ "Audiosession errore:% @", ошибка)} ' – rckoenes

+0

@rckoenes Я только что добавил журналы ошибок и предупреждений в исходное сообщение. – user717452

+0

похожие вопросы: http://stackoverflow.com/questions/19104728/itemfailedtoplaytoend-mpmovieplayercontroller-ios7 и http://stackoverflow.com/questions/19088955/ios7-issue-on-playing-mov-file-in-mpmovieplayerviewcontroller. У вашего имени файла есть пробелы? – Brenden

ответ

4

Попробуйте использовать

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

вместо

NSURL *newURL = [NSURL URLWithString:_entry.articleUrl]; 
Смежные вопросы