Use audio_session from pub.dev.

This commit is contained in:
Ryan Heise 2020-08-23 18:00:16 +10:00
parent 520bbb8656
commit a7cf6c103f
6 changed files with 18 additions and 15 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2019-2020 Ryan Heise. Copyright (c) 2019-2020 Ryan Heise and the project contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -11,9 +11,9 @@ packages:
audio_session: audio_session:
dependency: "direct main" dependency: "direct main"
description: description:
path: "../../audio_session" name: audio_session
relative: true url: "https://pub.dartlang.org"
source: path source: hosted
version: "0.0.1" version: "0.0.1"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive

View File

@ -7,8 +7,7 @@ environment:
flutter: ">=1.12.8 <2.0.0" flutter: ">=1.12.8 <2.0.0"
dependencies: dependencies:
audio_session: audio_session: ^0.0.1
path: ../../audio_session
flutter: flutter:
sdk: flutter sdk: flutter

View File

@ -532,13 +532,18 @@ class AudioPlayer {
/// [stop] playback on completion, you can call either method as soon as /// [stop] playback on completion, you can call either method as soon as
/// [processingState] becomes [ProcessingState.completed] by listening to /// [processingState] becomes [ProcessingState.completed] by listening to
/// [processingStateStream]. /// [processingStateStream].
///
/// This method activates the audio session before playback, and will do
/// nothing if activation of the audio session fails for any reason.
Future<void> play() async { Future<void> play() async {
if (playing) return; if (playing) return;
_playInterrupted = false; _playInterrupted = false;
final audioSession = await AudioSession.instance;
if (await audioSession.setActive(true)) {
_playingSubject.add(true); _playingSubject.add(true);
await AudioSession.ensurePrepared(ensureActive: true);
await _invokeMethod('play'); await _invokeMethod('play');
} }
}
/// Pauses the currently playing media. This method does nothing if /// Pauses the currently playing media. This method does nothing if
/// ![playing]. /// ![playing].

View File

@ -11,9 +11,9 @@ packages:
audio_session: audio_session:
dependency: "direct main" dependency: "direct main"
description: description:
path: "../audio_session" name: audio_session
relative: true url: "https://pub.dartlang.org"
source: path source: hosted
version: "0.0.1" version: "0.0.1"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive

View File

@ -8,8 +8,7 @@ environment:
flutter: ">=1.12.8 <2.0.0" flutter: ">=1.12.8 <2.0.0"
dependencies: dependencies:
audio_session: audio_session: ^0.0.1
path: ../audio_session
rxdart: ^0.24.1 rxdart: ^0.24.1
path: ^1.6.4 path: ^1.6.4
path_provider: ^1.6.10 path_provider: ^1.6.10