I found a very strange problem,
when downloading an mp3 file from local storage,
avplayeritem is always in an unknown state and cannot be played if the file is placed in the document folder.
method 1:
//AVAsset *asset = [[AVURLAsset alloc] initWithURL:_URL options:nil]; //AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:asset]; AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:_URL]; //line 1 while (playerItem.status!=AVPlayerItemStatusReadyToPlay && playerItem.status!=AVPlayerItemStatusFailed) { NSLog(@"avplayer: %@ status: %d", playerItem, playerItem.status); [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; } //line 2 NSLog(@"avplayer status: %d item: %@", playerItem.status, _URL); NSArray *metadata = [playerItem.asset commonMetadata];
method 2:
AVAsset *asset = [[AVURLAsset alloc] initWithURL:_URL options:nil]; AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:asset]; NSLog(@"avplayer status: %d item: %@", playerItem.status, _URL); NSArray *metadata = [playerItem.asset commonMetadata];
conclusion:
2015-03-19 00:42:49.243 goodnightfm[6737:353911] avplayer: <AVPlayerItem: 0x7fdc3bbd5c00, asset = <AVURLAsset: 0x7fdc3bbd8a50, URL = file:
but way2 code works well if the mp3 file was in the application bundle, even the status is still suck unknown
2015-03-19 00:45:35.977 goodnightfm[6783:355678] avplayer status: 0 item: file:
Iβm sure that the file in the application package and the document are the same, it can be played in any other software,
using way2, the only difference between the bundle & document file was the file
if an mp3 file is located in a package, this function can return metadata
NSArray *metadata = [playerItem.asset commonMetadata];
but return null using document url