Minor changes to v2 PR
This commit is contained in:
parent
8680cac01a
commit
c7543941c3
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue