rxlabz / audioplayer

A flutter plugin to play audio files iOS / Android / MacOS / Web ( Swift/Java )
https://pub.dartlang.org/packages/audioplayer
494 stars 189 forks source link

iOS - Physical volume buttons have no effect on audio volume #28

Open ozc opened 6 years ago

ozc commented 6 years ago

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

rxlabz commented 6 years ago

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 🤔

ozc commented 6 years ago

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.