1

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?

simonbs
  • 7,932
  • 13
  • 69
  • 115
  • Comparison of floating-point values using `==` looks scary. –  Aug 17 '12 at 20:44
  • That's true. I have corrected this. Should anyone be interested, here is a great post on how to avoid using the `==` operator. http://stackoverflow.com/a/1614761/486845. – simonbs Aug 17 '12 at 21:04

1 Answers1

1

This turned out to be an error due to the way the file was saved.

-playerWithURL: in AVPlayer works perfectly fine.

simonbs
  • 7,932
  • 13
  • 69
  • 115
  • I am having similar issues, what was the error (the way the file was saved), I think I just might be having the same error @simonbs – GangstaGraham Jul 23 '13 at 10:31