How to transfer audio from the URL of an iPhone application and change the volume using AVPlayer?

I am trying to transfer audio to an iPhone application. With AVPlayer, I can transfer audio from a URL with a few lines of code. However, I cannot change the volume using AVPlayer. Any help would be appreciated.

+5
source share
1 answer

you can change the volume according to the volume of resources, 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];
+1
source

All Articles