handleMethodCall method
Implementation
Future<dynamic> handleMethodCall(MethodCall call) async {
Map<String, dynamic> arguments = call.arguments ?? {};
final playerId = arguments['playerId'] ?? "0";
var player = getOrCreatePlayer(playerId);
print("------arguments: ${call.method}, player: $arguments");
switch (call.method) {
case "getPlatformVersion":
return "Browser ";
case "start":
final String url = arguments["url"];
// String title = arguments["title"];
// String desc = arguments["desc"];
// String cover = arguments["cover"];
bool isAuto = arguments["isAuto"] ?? false;
// bool isLocal = arguments["isLocal"] ?? false;
// bool isLocalCover = arguments["isLocalCover"] ?? false;
player = await start(playerId, url);
player.player?.autoplay = isAuto;
return 1;
case "playOrPause":
if (player.isPlaying) {
player.pause();
} else {
player.resume();
}
return player.isPlaying;
case "play":
player.resume();
return player.isPlaying;
case "pause":
player.pause();
return player.isPlaying;
case "stop":
player.stop();
break;
case 'release':
player.release();
return 1;
case "seekTo":
double position = call.arguments['position'] ?? 0;
player.seekTo(position);
break;
case 'rate':
double rate = call.arguments['rate'] ?? 1.0;
player.setRate(rate);
return 1;
case "setVolume":
double volume = call.arguments['volume'] ?? 1.0;
player.setVolume(volume);
break;
case "currentVolume":
return player.currentVolume;
case 'updateLrc':
default:
throw PlatformException(
code: 'Unimplemented',
details:
"The plugin for web doesn't implement the method '${call.method}'",
);
}
}