Handle audio interruptions by default.

This commit is contained in:
Ryan Heise 2020-08-25 15:17:49 +10:00
parent 60760d1010
commit 657fd300dd
3 changed files with 13 additions and 8 deletions

View File

@ -227,3 +227,8 @@ If you wish to connect to non-HTTPS URLS, add the following to your `Info.plist`
<true/>
</dict>
```
## Related plugins
* [audio_service](https://pub.dev/packages/audio_service): play any audio in the background and control playback from the lock screen, Android notifications, the iOS Control Center, and headset buttons.
* [audio_session](https://pub.dev/packages/audio_session): configure your app's audio category (e.g. music vs speech) and configure how your app interacts with other audio apps (e.g. audio focus, ducking, mixing).

View File

@ -54,7 +54,7 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
_player = AudioPlayer(handleInterruptions: true);
_player = AudioPlayer();
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.black,
));

View File

@ -68,13 +68,13 @@ class AudioPlayer {
bool _automaticallyWaitsToMinimizeStalling = true;
bool _playInterrupted = false;
/// Creates an [AudioPlayer].
///
/// Set [handleInterruptions] to `true` if you would like audio to be
/// automatically paused/ducked and resumed/unducked when audio interruptions
/// occur or when headphones are unplugged. You may may instead choose to
/// implement this behaviour yourself using the audio_session package.
factory AudioPlayer({bool handleInterruptions = false}) =>
/// Creates an [AudioPlayer]. The player will automatically pause/duck and
/// resume/unduck when audio interruptions occur (e.g. a phone call) or when
/// headphones are unplugged. If you wish to handle audio interruptions
/// manually, set [handleInterruptions] to `false` and interface directly
/// with the audio session via the
/// [audio_session](https://pub.dev/packages/audio_session) package.
factory AudioPlayer({bool handleInterruptions = true}) =>
AudioPlayer._internal(_uuid.v4(), handleInterruptions);
AudioPlayer._internal(this._id, bool handleInterruptions)