Add disposePlayer to web implementation.
This commit is contained in:
parent
bbbfdf3a4d
commit
ab1a4612b3
|
@ -1,3 +1,7 @@
|
|||
## 0.1.0
|
||||
|
||||
* Update to use platform interface 1.1.0.
|
||||
|
||||
## 0.0.1
|
||||
|
||||
* Migrated to the federated plugin model.
|
||||
|
|
|
@ -10,28 +10,37 @@ import 'package:just_audio_platform_interface/just_audio_platform_interface.dart
|
|||
final Random _random = Random();
|
||||
|
||||
class JustAudioPlugin extends JustAudioPlatform {
|
||||
final Map<String, JustAudioPlayer> players = {};
|
||||
|
||||
static void registerWith(Registrar registrar) {
|
||||
print("registerWith setting instance");
|
||||
JustAudioPlatform.instance = JustAudioPlugin();
|
||||
}
|
||||
|
||||
Future<AudioPlayerPlatform> init(InitRequest request) async {
|
||||
return Html5AudioPlayer(id: request.id);
|
||||
final player = Html5AudioPlayer(id: request.id);
|
||||
players[request.id] = player;
|
||||
return player;
|
||||
}
|
||||
|
||||
Future<DisposePlayerResponse> disposePlayer(
|
||||
DisposePlayerRequest request) async {
|
||||
await players[request.id]?.release();
|
||||
return DisposePlayerResponse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class JustAudioPlayer extends AudioPlayerPlatform {
|
||||
final String id;
|
||||
final eventController = StreamController<PlaybackEventMessage>();
|
||||
ProcessingStateMessage _processingState = ProcessingStateMessage.none;
|
||||
bool _playing = false;
|
||||
int _index;
|
||||
|
||||
JustAudioPlayer({@required this.id});
|
||||
JustAudioPlayer({@required String id}) : super(id);
|
||||
|
||||
@mustCallSuper
|
||||
Future<DisposeResponse> dispose(DisposeRequest request) async {
|
||||
Future<void> release() async {
|
||||
eventController.close();
|
||||
return DisposeResponse();
|
||||
}
|
||||
|
||||
Duration getCurrentPosition();
|
||||
|
@ -170,6 +179,7 @@ class Html5AudioPlayer extends JustAudioPlayer {
|
|||
|
||||
@override
|
||||
Future<LoadResponse> load(LoadRequest request) async {
|
||||
print("web load");
|
||||
_currentAudioSourcePlayer?.pause();
|
||||
_audioSourcePlayer = getAudioSource(request.audioSourceMessage);
|
||||
_index = 0;
|
||||
|
@ -180,6 +190,7 @@ class Html5AudioPlayer extends JustAudioPlayer {
|
|||
}
|
||||
|
||||
Future<Duration> loadUri(final Uri uri) async {
|
||||
print("loadUri $uri");
|
||||
transition(ProcessingStateMessage.loading);
|
||||
final src = uri.toString();
|
||||
if (src != _audioElement.src) {
|
||||
|
@ -198,6 +209,7 @@ class Html5AudioPlayer extends JustAudioPlayer {
|
|||
}
|
||||
transition(ProcessingStateMessage.ready);
|
||||
final seconds = _audioElement.duration;
|
||||
print("loadUri returning");
|
||||
return seconds.isFinite
|
||||
? Duration(milliseconds: (seconds * 1000).toInt())
|
||||
: null;
|
||||
|
@ -349,12 +361,13 @@ class Html5AudioPlayer extends JustAudioPlayer {
|
|||
Duration getDuration() => _currentAudioSourcePlayer?.duration;
|
||||
|
||||
@override
|
||||
Future<DisposeResponse> dispose(DisposeRequest request) async {
|
||||
Future<void> release() async {
|
||||
print("web release");
|
||||
_currentAudioSourcePlayer?.pause();
|
||||
_audioElement.removeAttribute('src');
|
||||
_audioElement.load();
|
||||
transition(ProcessingStateMessage.none);
|
||||
return await super.dispose(request);
|
||||
return await super.release();
|
||||
}
|
||||
|
||||
List<AudioSourcePlayer> getAudioSources(List messages) =>
|
||||
|
|
|
@ -7,14 +7,14 @@ packages:
|
|||
name: characters
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
version: "1.1.0-nullsafety.3"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.14.13"
|
||||
version: "1.15.0-nullsafety.3"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
@ -28,9 +28,9 @@ packages:
|
|||
just_audio_platform_interface:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: just_audio_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
path: "../just_audio_platform_interface"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.0.0"
|
||||
meta:
|
||||
dependency: "direct main"
|
||||
|
@ -38,7 +38,7 @@ packages:
|
|||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.8"
|
||||
version: "1.3.0-nullsafety.3"
|
||||
plugin_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -57,14 +57,14 @@ packages:
|
|||
name: typed_data
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
version: "1.3.0-nullsafety.3"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_math
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.8"
|
||||
version: "2.1.0-nullsafety.3"
|
||||
sdks:
|
||||
dart: ">=2.9.0-14.0.dev <3.0.0"
|
||||
dart: ">=2.10.0-110 <2.11.0"
|
||||
flutter: ">=1.12.13+hotfix.5"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
name: just_audio_web
|
||||
description: Web platform implementation of just_audio
|
||||
homepage: https://github.com/ryanheise/just_audio/tree/master/just_audio_web
|
||||
version: 0.0.1
|
||||
version: 0.1.0
|
||||
|
||||
flutter:
|
||||
plugin:
|
||||
|
@ -11,7 +11,9 @@ flutter:
|
|||
fileName: just_audio_web.dart
|
||||
|
||||
dependencies:
|
||||
just_audio_platform_interface: ^1.0.0
|
||||
# just_audio_platform_interface: ^1.0.0
|
||||
just_audio_platform_interface:
|
||||
path: ../just_audio_platform_interface
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_web_plugins:
|
||||
|
|
Loading…
Reference in New Issue