Reputation: 5679
I would like to know why my AVPlayer crashes when I want it to play "some" songs.
That is the way I play these songs:
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];
I have some KVO observers, one of them observes AVPlayer status
and when I try to play one of these songs it gives me an error:
Domain=AVFoundationErrorDomain Code=-11800
UserInfo=0x1cdc3be0 {NSLocalizedDescription=..., NSUnderlyingError=0x1cdc14c0
"The operation couldn’t be completed. (OSStatus error -303.)"
Is there a way to play these songs? Any help is appreciated.
EDIT: I have succeeded to make these songs play well
__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];
});
});
Upvotes: 1
Views: 1261
Reputation: 5679
__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];
});
});
This way it works
Upvotes: 1