AVPlayer replaceCurrentItemWithPlayerItem not working on iOS 4.3.3+

前端 未结 2 1809
予麋鹿
予麋鹿 2021-02-19 04:35

I have an audio player that I\'m building using AVPlayer.

Currently, I keep the player instance around and when I need to swap tracks (either from a manual

2条回答
  •  难免孤独
    2021-02-19 05:03

    I've been experiencing similar problems. You probably got started from AVPlayerDemoPlaybackViewController from Apple sample code like me. Maybe the problem why currentItem is nil is because it's not loaded yet or ready for playback (my problem was I couldn't get the duration of the new AVPlayerItem).

    You could try starting the playback when observed status of the currentItem is ReadyToPlay.

    AVPlayerStatus status = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
        switch (status) {
            case AVPlayerStatusUnknown: {
                NSLog(@"PLAYER StatusUnknown");
            }
                break;
            case AVPlayerStatusReadyToPlay: {
                NSLog(@"PLAYER ReadyToPlay");
                [self play];
            }
                break;
            case AVPlayerStatusFailed: {
                AVPlayerItem *playerItem = (AVPlayerItem *)object;
                [self handleError: [playerItem.error localizedDescription]];
            }
                break;
        }
    

    I don't know if this will wok for you, I didn't try this on lower or higher than 4.3.4 iPad, so I guess I'll run into complications soon.

提交回复
热议问题