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

View File

@ -13,13 +13,13 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
public class JustAudioPlugin implements FlutterPlugin {
private MethodChannel channel;
private MethodCallHandlerImpl methodCallHandler;
private MainMethodCallHandler methodCallHandler;
public JustAudioPlugin() {
}
/**
* Plugin registration.
* v1 plugin registration.
*/
public static void registerWith(Registrar registrar) {
final JustAudioPlugin plugin = new JustAudioPlugin();
@ -42,7 +42,7 @@ public class JustAudioPlugin implements FlutterPlugin {
}
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.setMethodCallHandler(methodCallHandler);

View File

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

View File

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