Add disposePlayer to platform interface. Retain player.position after dispose.
This commit is contained in:
parent
35a6e4810b
commit
ad9e4518cf
11 changed files with 87 additions and 97 deletions
|
@ -41,6 +41,11 @@ abstract class JustAudioPlatform extends PlatformInterface {
|
|||
Future<AudioPlayerPlatform> init(InitRequest request) {
|
||||
throw UnimplementedError('init() has not been implemented.');
|
||||
}
|
||||
|
||||
/// Disposes of a platform player.
|
||||
Future<DisposePlayerResponse> disposePlayer(DisposePlayerRequest request) {
|
||||
throw UnimplementedError('disposePlayer() has not been implemented.');
|
||||
}
|
||||
}
|
||||
|
||||
/// A nested platform interface for communicating with a particular player
|
||||
|
@ -53,6 +58,10 @@ abstract class JustAudioPlatform extends PlatformInterface {
|
|||
/// `implements` this interface will be broken by newly added
|
||||
/// [AudioPlayerPlatform] methods.
|
||||
abstract class AudioPlayerPlatform {
|
||||
final String id;
|
||||
|
||||
AudioPlayerPlatform(this.id);
|
||||
|
||||
Stream<PlaybackEventMessage> get playbackEventMessageStream {
|
||||
throw UnimplementedError(
|
||||
'playbackEventMessageStream has not been implemented.');
|
||||
|
@ -103,6 +112,9 @@ abstract class AudioPlayerPlatform {
|
|||
"setAndroidAudioAttributes() has not been implemented.");
|
||||
}
|
||||
|
||||
/// This method has been superceded by [JustAudioPlatform.disposePlayer].
|
||||
/// For backward compatibility, this method will still be called as a
|
||||
/// fallback if [JustAudioPlatform.disposePlayer] is not implemented.
|
||||
Future<DisposeResponse> dispose(DisposeRequest request) {
|
||||
throw UnimplementedError("dispose() has not been implemented.");
|
||||
}
|
||||
|
@ -244,6 +256,21 @@ class InitRequest {
|
|||
};
|
||||
}
|
||||
|
||||
class DisposePlayerRequest {
|
||||
final String id;
|
||||
|
||||
DisposePlayerRequest({@required this.id});
|
||||
|
||||
Map<dynamic, dynamic> toMap() => {
|
||||
'id': id,
|
||||
};
|
||||
}
|
||||
|
||||
class DisposePlayerResponse {
|
||||
static DisposePlayerResponse fromMap(Map<dynamic, dynamic> map) =>
|
||||
DisposePlayerResponse();
|
||||
}
|
||||
|
||||
class LoadRequest {
|
||||
final AudioSourceMessage audioSourceMessage;
|
||||
|
||||
|
|
|
@ -13,15 +13,22 @@ class MethodChannelJustAudio extends JustAudioPlatform {
|
|||
await _mainChannel.invokeMethod('init', request.toMap());
|
||||
return MethodChannelAudioPlayer(request.id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DisposePlayerResponse> disposePlayer(
|
||||
DisposePlayerRequest request) async {
|
||||
return DisposePlayerResponse.fromMap(
|
||||
await _mainChannel.invokeMethod('disposePlayer', request.toMap()));
|
||||
}
|
||||
}
|
||||
|
||||
/// An implementation of [AudioPlayerPlatform] that uses method channels.
|
||||
class MethodChannelAudioPlayer extends AudioPlayerPlatform {
|
||||
final String id;
|
||||
final MethodChannel _channel;
|
||||
|
||||
MethodChannelAudioPlayer(this.id)
|
||||
: _channel = MethodChannel('com.ryanheise.just_audio.methods.$id');
|
||||
MethodChannelAudioPlayer(String id)
|
||||
: _channel = MethodChannel('com.ryanheise.just_audio.methods.$id'),
|
||||
super(id);
|
||||
|
||||
@override
|
||||
Stream<PlaybackEventMessage> get playbackEventMessageStream =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue