audioplayer icon indicating copy to clipboard operation
audioplayer copied to clipboard

iOS - Physical volume buttons have no effect on audio volume

Open ozc opened this issue 7 years ago • 2 comments

Physical volume buttons did not have any effect on the audio volume. These codes I've stumbled on StackOverflow seem like working. I have nearly zero knowledge on ios programming. I don't know if it's the right place, but I've added the to - (id) init method.

It would be good to have system volume getter and setter methods too. So it will be easier to add onscreen volume controls, like a volume slider.

- (id)init {
  self = [super init];
  if (self) {
      players = [[NSMutableDictionary alloc] init];
  }

  AudioSessionInitialize (NULL, NULL, NULL, NULL);
  UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
  AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory);
  AudioSessionSetActive (true);

  return self;
}

https://stackoverflow.com/questions/18541139/ios-avaudioplayer-volume-control

https://stackoverflow.com/questions/16474771/cannot-control-volume-of-avaudioplayer-via-hardware-buttons-when-audiosessionact

ozc avatar Apr 13 '18 20:04 ozc

hi, I've just test the example app on a 10.3 and 11.2 devices, and the physical buttons seems correctly working in my case 🤔

rxlabz avatar Apr 21 '18 14:04 rxlabz

I don't know if it's about the Simulator or not. Before adding these lines to the app running on Simulator 11.3 (15E217) with streaming audio (aacp), volume up and down buttons showed volume change popup, but had no effect on the audio volume.

On Android, aacp streams could not be played. So, I've changed MediaPlayer with Exoplayer 2. I'm going to add foreground service too. After testing it I'll send the changes.

ozc avatar Apr 22 '18 01:04 ozc