setMethodCallHandler method

void setMethodCallHandler()

Implementation

void setMethodCallHandler() async {
  _methodChannel.setMethodCallHandler((call) async {
    switch (call.method) {
      case Constants.onCurrentDuration:
        var duration = call.arguments[Constants.current];
        var key = call.arguments[Constants.playerKey];
        if (duration.runtimeType == int) {
          var indentifier = PlayerIdentifier<int>(key, duration);
          PlatformStreams.instance.addCurrentDurationEvent(indentifier);
        }
        break;
      case Constants.onDidFinishPlayingAudio:
        var key = call.arguments[Constants.playerKey];
        var playerState = (call.arguments[Constants.finishtype] is int) &&
                call.arguments[Constants.finishtype] == 0
            ? PlayerState.playing
            : call.arguments[Constants.finishtype] == 1
                ? PlayerState.paused
                : PlayerState.stopped;
        var indentifier = PlayerIdentifier<PlayerState>(key, playerState);
        PlatformStreams.instance.addPlayerStateEvent(indentifier);
        if (PlatformStreams.instance.playerControllerFactory[key] != null) {
          PlatformStreams.instance.playerControllerFactory[key]
              ?._playerState = playerState;
        }
        break;
    }
  });
}