AudioPlayer constructor

AudioPlayer({
  1. String? playerId,
})

Creates a new instance and assigns an unique id to it.

Implementation

AudioPlayer({String? playerId}) : playerId = playerId ?? _uuid.v4() {
  _onLogStreamSubscription = onLog.listen(
    (log) => AudioLogger.log('$log\nSource: $_source'),
    onError: (Object e, [StackTrace? stackTrace]) => AudioLogger.error(
      AudioPlayerException(this, cause: e),
      stackTrace,
    ),
  );
  _onPlayerCompleteStreamSubscription = onPlayerComplete.listen(
    (_) async {
      state = PlayerState.completed;
      if (releaseMode == ReleaseMode.release) {
        _source = null;
      }
      await _positionUpdater?.stopAndUpdate();
    },
    onError: (Object _, [StackTrace? __]) {
      /* Errors are already handled via log stream */
    },
  );
  _create();
  positionUpdater = FramePositionUpdater(
    getPosition: getCurrentPosition,
  );
}