1

I've developed an iOS app that plays two separate audio streams simultaneously. To do this I am using AVPlayer thus:

//Use URL to set up the speech radio player.
NSURL *urlStreamSpeech = [NSURL URLWithString:self.urlAddressSpeech];
playerSpeech = [AVPlayer playerWithURL:urlStreamSpeech];

//Use URL to set up the music player.    
NSURL *urlStreamMusic = [NSURL URLWithString:self.urlAddressMusic];
playerMusic = [AVPlayer playerWithURL:urlStreamMusic];

I am now trying to implement a volume control so that the user will be able to control the volume for the audio streams individually. As I've tried this I have come to the conclusion that there is no volume property for the AVPlayer class. I also looked at the AVAudioPlayer class, but from what I gather that class is only able to play local audio files, not streamed audio.

So my question is: how can I control the volume of streamed audio on iOS?

Andreas
  • 11
  • 3

2 Answers2

0
NSString* resourcePath = url; //your url
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]];
NSError *error;

app.audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
app.audioPlayer.numberOfLoops = 0;
app.audioPlayer.volume = 1.0f;
[app.audioPlayer prepareToPlay];

if (app.audioPlayer == nil)
    NSLog(@"%@", [error description]);
else
    [app.audioPlayer play];

Look into the AVPlayer class, part of the AVFoundation framework... this is the objective-c (iOS) class you use for streaming audio.

look at this post Live streaming

NewStack
  • 990
  • 8
  • 19
  • Thanks navinsillu, but according to the Apple's documentation the AVAudioPlayer class does not provide support for streaming audio based on HTTP URL's. The URL used with initWithContentsOfURL: must be a File URL (file://). That is, a local path. I also don't want to download a remote file into a NSData object since what I'm doing is streaming infinite remote audio streams over HTTP (currently using AVPlayer which doesn't have the volume property I need). Hence I don't think this solves my problem. – Andreas Feb 01 '13 at 11:17
0
MPMusicPlayerController* musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
[musicPlayer setVolume:[SliderVolumen value]];

Only work in the device, no simulator.

Compatible with AVPlayer.

zero323
  • 322,348
  • 103
  • 959
  • 935