Handle audio interruptions by default.
This commit is contained in:
parent
60760d1010
commit
657fd300dd
|
@ -227,3 +227,8 @@ If you wish to connect to non-HTTPS URLS, add the following to your `Info.plist`
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</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).
|
||||||
|
|
|
@ -54,7 +54,7 @@ class _MyAppState extends State<MyApp> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_player = AudioPlayer(handleInterruptions: true);
|
_player = AudioPlayer();
|
||||||
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
||||||
statusBarColor: Colors.black,
|
statusBarColor: Colors.black,
|
||||||
));
|
));
|
||||||
|
|
|
@ -68,13 +68,13 @@ class AudioPlayer {
|
||||||
bool _automaticallyWaitsToMinimizeStalling = true;
|
bool _automaticallyWaitsToMinimizeStalling = true;
|
||||||
bool _playInterrupted = false;
|
bool _playInterrupted = false;
|
||||||
|
|
||||||
/// Creates an [AudioPlayer].
|
/// Creates an [AudioPlayer]. The player will automatically pause/duck and
|
||||||
///
|
/// resume/unduck when audio interruptions occur (e.g. a phone call) or when
|
||||||
/// Set [handleInterruptions] to `true` if you would like audio to be
|
/// headphones are unplugged. If you wish to handle audio interruptions
|
||||||
/// automatically paused/ducked and resumed/unducked when audio interruptions
|
/// manually, set [handleInterruptions] to `false` and interface directly
|
||||||
/// occur or when headphones are unplugged. You may may instead choose to
|
/// with the audio session via the
|
||||||
/// implement this behaviour yourself using the audio_session package.
|
/// [audio_session](https://pub.dev/packages/audio_session) package.
|
||||||
factory AudioPlayer({bool handleInterruptions = false}) =>
|
factory AudioPlayer({bool handleInterruptions = true}) =>
|
||||||
AudioPlayer._internal(_uuid.v4(), handleInterruptions);
|
AudioPlayer._internal(_uuid.v4(), handleInterruptions);
|
||||||
|
|
||||||
AudioPlayer._internal(this._id, bool handleInterruptions)
|
AudioPlayer._internal(this._id, bool handleInterruptions)
|
||||||
|
|
Loading…
Reference in New Issue