我想知道为什么我的AVPlayer在我想播放“一些”歌曲时会崩溃。
这就是我播放这些歌曲的方式:
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];
});
});
答案 0 :(得分: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];
});
});
这种方式有效