2

Good Day,

I am working on one Radio APP that gets shoutcast streaming .pls file and plays it with help of AVFoundation framework.

This job is easily done with AVPlayer, but the problem with it is that I can not code or find any good solution to get it working with volume slider, the AVPlayer class does not have volume property.

So now I am trying to get it working with AVAudioPlayer which has volume property, and here is my code:

NSString *resourcePatch = @"http://vibesradio.org:8002/listen.pls";
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePatch]];
NSError *error;

vPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
vPlayer.numberOfLoops = 0;
vPlayer.volume = 1.0f;
if (vPlayer == nil)
    NSLog(@"%@", [error description]);
else
    [vPlayer play];

This code is working with uploaded .mp3 files on my server but it is not working with .pls files generated by shoutcast,

Is there any way to fix AVAudioPlayer to work with .pls files, or implement volume slider to AVPlayer ?

EmilDo
  • 1,177
  • 3
  • 16
  • 33
  • Have you tried loading the actual stream resource, rather than the playlist? `.pls` files are just playlists that contain URLs to the actual streams. They cannot be played directly. – Brad Nov 18 '12 at 05:39

1 Answers1

1

Using AVAudioPlayer for stream from network is not a good idea. See what Apple's documentation say on AVAudioPlayer:

An instance of the AVAudioPlayer class, called an audio player, provides playback of audio data from a file or memory.

Apple recommends that you use this class for audio playback unless you are playing audio captured from a network stream or require very low I/O latency.

For change AVPlayer's volume check this question:Adjusting the volume of a playing AVPlayer

Community
  • 1
  • 1
sunkehappy
  • 8,970
  • 5
  • 44
  • 65