Reputation: 557
NSURL* fileURL=[_musicListViewModel fileURLWithModel:model];
NSData* assetData=[NSData dataWithContentsOfURL:fileURL];
AVAudioPlayer* audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
[audioPlayer play];
AVAsset*asset=[AVURLAsset URLAssetWithURL:fileURL options:nil];
AVAsset* asset=[AVAsset assetWithURL:fileURL];
if (!asset.playable){
[self playerErrorHandler];
return;
}
fileURL is file:///var/mobile/Containers/Data/Application/5A0A1FF9-F884-4CB9-9F59-BBFCB7C51A1B/Documents/music_data_path/yI3a6r
.
And assetData is not nil.
audioPlayer can play from the file while both asset initialization cannot make itself playable.
WRONG: SUFFIX is ESSENTIAL
Suffix of audio file is .mp3, but it doesn't work when I append suffix to file path.
What's wrong with my code???
Upvotes: 2
Views: 1530
Reputation: 557
Finally, I find that suffix is essential in filePath, or AVAsset will not playable, which doesn't like AVAudioPlayer.
Upvotes: 2