Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: remove unused defaultToSpeaker in AudioContextIOS and replace with AVAudioSessionOptions.defaultToSpeaker #1374

Merged
merged 3 commits into from
Jan 10, 2023

Conversation

Gustl22
Copy link
Collaborator

@Gustl22 Gustl22 commented Jan 10, 2023

Description

  • The parameter defaultToSpeaker was not used in AudioContextIOS. Instead option: [AVAudioSessionOptions.defaultToSpeaker] should be used
  • AudioContext now has default configurations for iOS and android. Nevertheless it is recommended to set the config via AudioContextConfig.build().

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs:, chore: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation and added dartdoc comments with ///, where necessary.
  • I have updated/added relevant examples in example.

Breaking Change

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

Migration instructions

Old:

  AudioPlayer.global.setGlobalAudioContext(
    AudioContext(
      iOS: AudioContextIOS(
        defaultToSpeaker: true,
        category: AVAudioSessionCategory.playback,
        options: [AVAudioSessionOptions.mixWithOthers],
      ),
      android: AudioContextAndroid(
        isSpeakerphoneOn: true,
        stayAwake: true,
        contentType: AndroidContentType.music,
        usageType: AndroidUsageType.media,
        audioFocus: AndroidAudioFocus.gain,
      ),
    ),
  );

New:

  AudioPlayer.global.setGlobalAudioContext(
    AudioContext(
      iOS: AudioContextIOS(
        category: AVAudioSessionCategory.playback,
        options: [
          AVAudioSessionOptions.mixWithOthers,
          AVAudioSessionOptions.defaultToSpeaker,
        ],
      ),
    ),
  );

Instead of setting defaultToSpeaker in AudioContextIOS, use the option: [AVAudioSessionOptions.defaultToSpeaker].

Related Issues

Closes #1194
Related to #1363

@Gustl22 Gustl22 requested a review from luanpotter January 10, 2023 10:28
@Gustl22
Copy link
Collaborator Author

Gustl22 commented Jan 10, 2023

@lukepighetti you can test this by adding following lines to your pubspec.yaml in your project:

dependency_overrides:
  audioplayers:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers'
      ref: '1499a51037e900b7a41ef3514803db8472ed767f'
  audioplayers_platform_interface:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers_platform_interface'
      ref: '1499a51037e900b7a41ef3514803db8472ed767f'
  audioplayers_darwin:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers_darwin'
      ref: '1499a51037e900b7a41ef3514803db8472ed767f'

@spydon
Copy link
Member

spydon commented Jan 10, 2023

@lukepighetti you can test this by adding following lines to your pubspec.yaml in your project:

dependency_overrides:
  audioplayers:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers'
      ref: '1499a51037e900b7a41ef3514803db8472ed767f'
  audioplayers_platform_interface:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers_platform_interface'
      ref: '1499a51037e900b7a41ef3514803db8472ed767f'
  audioplayers_darwin:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers_darwin'
      ref: '1499a51037e900b7a41ef3514803db8472ed767f'

Or @OlegNovosad

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's hope this solves it once and for all, it probably will! 🙏

Copy link
Member

@luanpotter luanpotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for fixing this correctly @Gustl22

@spydon spydon merged commit d844ef9 into main Jan 10, 2023
@spydon spydon deleted the gustl22/1194-fix-ios-audio-config branch January 10, 2023 15:06
@Gustl22 Gustl22 restored the gustl22/1194-fix-ios-audio-config branch January 10, 2023 15:26
@Gustl22 Gustl22 deleted the gustl22/1194-fix-ios-audio-config branch January 11, 2023 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iOS volume very low (sound is coming from earpiece)
3 participants