1

我想知道为什么当我想让它播放“一些”歌曲时我的 AVPlayer 崩溃。

歌曲#1

歌曲#2

这就是我演奏这些歌曲的方式:

AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:@"http://www.iwheelbuy.com/Player/Test/1.mp3"]];
AVPlayer *player = [[AVPlayer alloc] init];
[player replaceCurrentItemWithPlayerItem:item];
[player setRate:1.0f];

我有一些 KVO 观察者,其中一个观察者,AVPlayer status当我尝试播放其中一首歌曲时,它给了我一个错误:

Domain=AVFoundationErrorDomain Code=-11800
UserInfo=0x1cdc3be0 {NSLocalizedDescription=..., NSUnderlyingError=0x1cdc14c0
"The operation couldn’t be completed. (OSStatus error -303.)"

有没有办法播放这些歌曲?任何帮助表示赞赏。

编辑:我已经成功地让这些歌曲播放得很好

__block AVPlayer *currentPlayerBlock = _currentPlayer;
__block NSURL *urlBlock = url;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:urlBlock options:nil];
    AVPlayerItem *item = [[AVPlayerItem alloc] initWithAsset:asset];
    dispatch_sync(dispatch_get_main_queue(), ^{
        [currentPlayerBlock replaceCurrentItemWithPlayerItem:item];
        [currentPlayerBlock setRate:1.0f];
    });
});
4

1 回答 1

1
__block AVPlayer *currentPlayerBlock = _currentPlayer;
__block NSURL *urlBlock = url;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:urlBlock options:nil];
    AVPlayerItem *item = [[AVPlayerItem alloc] initWithAsset:asset];
    dispatch_sync(dispatch_get_main_queue(), ^{
        [currentPlayerBlock replaceCurrentItemWithPlayerItem:item];
        [currentPlayerBlock setRate:1.0f];
    });
});

这样工作

于 2013-04-03T01:55:46.983 回答