Reputation: 8042
I am downloading an MP3 file using NSURLConnection
and I save the data to a file using NSFileHandle
. Whenever a certain percentage of the file is downloaded (all the files are roughly the same size), I will start playing the MP3 file.
I thought that I could use the AVPlayer
to do this but it doesn't work on a device - only in simulator.
I do the following:
if (self.player.rate == 0.0f && percentage > kMinimumDownloadPercentage)
{
NSError *error;
self.player = [AVPlayer playerWithURL:[[NSURL alloc] initFileURLWithPath:localPath]];
if (!error)
[self.player play];
else
NSLog(@"%@", error);
}
This works in simulator but not on device. No error is given. It does work if I do the following, though:
self.player = [AVPlayer playerWithURL:url];
Where url
is the remote URL to the MP3 file.
Does anyone know why I can't play the local file using AVPlayer
?
Upvotes: 1
Views: 1442
Reputation: 8042
This turned out to be an error due to the way the file was saved.
-playerWithURL:
in AVPlayer
works perfectly fine.
Upvotes: 1