0

I've been searching for a good tutorial for playing and streaming audio finally I found this which seems to offer an offline audio playing.

in the YMCAudioPlayer class I've commented loading a resource and provided NSURL* generated by a direct link instead like so.

- (void)initPlayer:(NSString*) audioFile fileExtension:(NSString*)fileExtension
{
    //NSURL *audioFileLocationURL = [[NSBundle mainBundle] URLForResource:audioFile withExtension:fileExtension];
    NSURL *audioFileLocationURL = [NSURL URLWithString:@"http://188.95.64.47/AghaninaDownload/Content/per_singer/JFire/Audios/J-FirE_and_Omar_khalid_wlaKelmeh-sample.mp3"];
    NSError *error;
    self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileLocationURL error:&error];
}

And I've ensured that it's a valid link, but seems not to play on emulator. what have I missed there?

EDIT

It generates the following error

 Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)
Ahmad Dwaik 'Warlock'
  • 5,953
  • 5
  • 34
  • 56
  • Why don't You download the mp3 on disk while streaming hope this helps you https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Streams/Articles/ReadingInputStreams.html#//apple_ref/doc/uid/20002273-BCIJHAGD – Bobj-C May 20 '14 at 08:53
  • Isn't there a direct stream method instead of download and play? – Ahmad Dwaik 'Warlock' May 20 '14 at 09:14

3 Answers3

0

Might be a stupid question, but did you make it play ?

[self.audioPlayer play];

Then I would try this, to ensure your settings are correct :

[self.audioPlayer prepareToPlay];

[self.audioPlayer setCurrentTime:0.0];

[self.audioPlayer setVolume:1.0];

[self.audioPlayer play];

You can also use the delegate of AVAudioPlayer to check if something happens when you play.

Else it might be an URL of format issue.

Kujey
  • 1,122
  • 6
  • 17
0

I think you cannot play audio on EMULATOR, you have to test it on device.

Here mentioned on apple developer guid -

https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/iOS_Simulator_Guide/TestingontheiOSSimulator/TestingontheiOSSimulator.html#//apple_ref/doc/uid/TP40012848-CH4-SW1

brainless coder
  • 6,310
  • 1
  • 20
  • 36
-1

I've found the answer in the accepted answer here

"I was able to fix the issue by loading the file first into an NSData element and then using that to initialize the AVAudioPlayer instead, like so:"

NSData *songFile = [[NSData alloc] initWithContentsOfURL:songCacheURL options:NSDataReadingMappedIfSafe error:&error1 ];
self.audioPlayer = [[AVAudioPlayer alloc] initWithData:songFile error:&error2];
Community
  • 1
  • 1
Ahmad Dwaik 'Warlock'
  • 5,953
  • 5
  • 34
  • 56
  • 3
    That is a horrible solution and you wont be streaming at all using this variant. Not even a progressive download playback. Switch to `AVPlayer` instead of `AVAudioPlayer` as the latter does not support HTTP streaming but the former does. – Till May 20 '14 at 10:07