subscribePlayerState static method

Stream<PlayerState> subscribePlayerState()

Subscribes to the PlayerState and returns it.

Throws a PlatformException if this fails Throws a MissingPluginException if the method is not implemented on the native platforms.

Implementation

static Stream<PlayerState> subscribePlayerState() {
  try {
    var playerStateSubscription =
        _playerStateChannel.receiveBroadcastStream();
    return playerStateSubscription.asyncMap((playerStateJson) {
      var playerStateMap =
          jsonDecode(playerStateJson.toString()) as Map<String, dynamic>;
      return PlayerState.fromJson(playerStateMap);
    });
  } on Exception catch (e) {
    _logException(MethodNames.subscribePlayerState, e);
    rethrow;
  }
}