Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stream audio from a URL for an iPhone app and change volume using AVPlayer?

I am trying to stream audio for an iPhone app. With the AVPlayer, I can stream audio from a URL with a few lines of code. I cannot change the volume with the AVPlayer though. Any help would be appreciated.

like image 495
user1530580 Avatar asked Nov 13 '22 10:11

user1530580


1 Answers

you can change volume by property volume, see below code

NSString* resourcePath = url; //your url
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]];
    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
        audioPlayer.numberOfLoops = 0;
        audioPlayer.volume = 5.0f;  //set volume here
        [audioPlayer prepareToPlay];
like image 153
Ravindra Bagale Avatar answered Nov 15 '22 07:11

Ravindra Bagale