Implement disposePlayer on Android.
This commit is contained in:
parent
8d1375f03c
commit
70a8dbc5b7
|
@ -108,12 +108,8 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
|
|||
}
|
||||
};
|
||||
|
||||
private final Runnable onDispose;
|
||||
|
||||
public AudioPlayer(final Context applicationContext, final BinaryMessenger messenger,
|
||||
final String id, final Runnable onDispose) {
|
||||
public AudioPlayer(final Context applicationContext, final BinaryMessenger messenger, final String id) {
|
||||
this.context = applicationContext;
|
||||
this.onDispose = onDispose;
|
||||
methodChannel = new MethodChannel(messenger, "com.ryanheise.just_audio.methods." + id);
|
||||
methodChannel.setMethodCallHandler(this);
|
||||
eventChannel = new EventChannel(messenger, "com.ryanheise.just_audio.events." + id);
|
||||
|
@ -323,10 +319,6 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
|
|||
Integer index = (Integer)request.get("index");
|
||||
seek(position == null ? C.TIME_UNSET : position / 1000, result, index);
|
||||
break;
|
||||
case "dispose":
|
||||
dispose();
|
||||
result.success(new HashMap<String, Object>());
|
||||
break;
|
||||
case "concatenatingInsertAll":
|
||||
concatenating(request.get("id"))
|
||||
.addMediaSources((Integer)request.get("index"), getAudioSources(request.get("children")), handler, () -> result.success(new HashMap<String, Object>()));
|
||||
|
@ -681,7 +673,6 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
|
|||
}
|
||||
|
||||
public void dispose() {
|
||||
if (player == null) return;
|
||||
mediaSources.clear();
|
||||
mediaSource = null;
|
||||
loopingChildren.clear();
|
||||
|
@ -693,7 +684,6 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
|
|||
if (eventSink != null) {
|
||||
eventSink.endOfStream();
|
||||
}
|
||||
onDispose.run();
|
||||
}
|
||||
|
||||
private void abortSeek() {
|
||||
|
|
|
@ -26,15 +26,24 @@ public class MainMethodCallHandler implements MethodCallHandler {
|
|||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall call, @NonNull Result result) {
|
||||
switch (call.method) {
|
||||
case "init":
|
||||
final Map<?, ?> request = call.arguments();
|
||||
switch (call.method) {
|
||||
case "init": {
|
||||
String id = (String)request.get("id");
|
||||
players.put(id, new AudioPlayer(applicationContext, messenger, id,
|
||||
() -> players.remove(id)
|
||||
));
|
||||
players.put(id, new AudioPlayer(applicationContext, messenger, id));
|
||||
result.success(null);
|
||||
break;
|
||||
}
|
||||
case "disposePlayer": {
|
||||
String id = (String)request.get("id");
|
||||
AudioPlayer player = players.get(id);
|
||||
if (player != null) {
|
||||
player.dispose();
|
||||
players.remove(id);
|
||||
}
|
||||
result.success(new HashMap<String, Object>());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
result.notImplemented();
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue