Minor changes to v2 PR

This commit is contained in:
Ryan Heise 2020-06-08 21:53:05 +10:00
parent 8680cac01a
commit c7543941c3
4 changed files with 9 additions and 10 deletions

View File

@ -278,7 +278,6 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met
break; break;
case "dispose": case "dispose":
dispose(); dispose();
onDispose.run();
result.success(null); result.success(null);
break; break;
default: default:
@ -518,6 +517,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met
buffering = false; buffering = false;
transition(PlaybackState.none); transition(PlaybackState.none);
} }
onDispose.run();
} }
private void abortSeek() { private void abortSeek() {

View File

@ -13,13 +13,13 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
public class JustAudioPlugin implements FlutterPlugin { public class JustAudioPlugin implements FlutterPlugin {
private MethodChannel channel; private MethodChannel channel;
private MethodCallHandlerImpl methodCallHandler; private MainMethodCallHandler methodCallHandler;
public JustAudioPlugin() { public JustAudioPlugin() {
} }
/** /**
* Plugin registration. * v1 plugin registration.
*/ */
public static void registerWith(Registrar registrar) { public static void registerWith(Registrar registrar) {
final JustAudioPlugin plugin = new JustAudioPlugin(); final JustAudioPlugin plugin = new JustAudioPlugin();
@ -42,7 +42,7 @@ public class JustAudioPlugin implements FlutterPlugin {
} }
private void startListening(Context applicationContext, BinaryMessenger messenger) { private void startListening(Context applicationContext, BinaryMessenger messenger) {
methodCallHandler = new MethodCallHandlerImpl(applicationContext, messenger); methodCallHandler = new MainMethodCallHandler(applicationContext, messenger);
channel = new MethodChannel(messenger, "com.ryanheise.just_audio.methods"); channel = new MethodChannel(messenger, "com.ryanheise.just_audio.methods");
channel.setMethodCallHandler(methodCallHandler); channel.setMethodCallHandler(methodCallHandler);

View File

@ -8,16 +8,17 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.MethodChannel.Result;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
public class MethodCallHandlerImpl implements MethodCallHandler { public class MainMethodCallHandler implements MethodCallHandler {
private final Context applicationContext; private final Context applicationContext;
private final BinaryMessenger messenger; private final BinaryMessenger messenger;
private final Map<String, AudioPlayer> players = new HashMap<>(); private final Map<String, AudioPlayer> players = new HashMap<>();
public MethodCallHandlerImpl(Context applicationContext, public MainMethodCallHandler(Context applicationContext,
BinaryMessenger messenger) { BinaryMessenger messenger) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.messenger = messenger; this.messenger = messenger;
@ -44,10 +45,8 @@ public class MethodCallHandlerImpl implements MethodCallHandler {
} }
void dispose() { void dispose() {
for (AudioPlayer player : players.values()) { for (AudioPlayer player : new ArrayList<AudioPlayer>(players.values())) {
player.dispose(); player.dispose();
} }
players.clear();
} }
} }

View File

@ -451,7 +451,7 @@ class AudioPlayer {
/// * [AudioPlaybackState.none] /// * [AudioPlaybackState.none]
/// * [AudioPlaybackState.connecting] /// * [AudioPlaybackState.connecting]
Future<void> dispose() async { Future<void> dispose() async {
await _invokeMethod('dispose', [_id]); await _invokeMethod('dispose');
if (_cacheFile?.existsSync() == true) { if (_cacheFile?.existsSync() == true) {
_cacheFile?.deleteSync(); _cacheFile?.deleteSync();
} }