part of 'audio_player.dart'; mixin RhythmAudioPlayersStreams on AudioPlayerInterface { // stream getters Stream get durationStream { // if (mkSupportedPlatform) { return _mkPlayer.stream.duration; // } else { // return _justAudio!.durationStream // .where((event) => event != null) // .map((event) => event!) // ; // } } Stream get positionStream { // if (mkSupportedPlatform) { return _mkPlayer.stream.position; // } else { // return _justAudio!.positionStream; // } } Stream get bufferedPositionStream { // if (mkSupportedPlatform) { // audioplayers doesn't have the capability to get buffered position return _mkPlayer.stream.buffer; // } else { // return _justAudio!.bufferedPositionStream; // } } Stream get completedStream { // if (mkSupportedPlatform) { return _mkPlayer.stream.completed; // } else { // return _justAudio!.playerStateStream // .where( // (event) => event.processingState == ja.ProcessingState.completed) // ; // } } /// Stream that emits when the player is almost (%) complete Stream percentCompletedStream(double percent) { return positionStream .asyncMap( (position) async => duration == Duration.zero ? 0 : (position.inSeconds / duration.inSeconds * 100).toInt(), ) .where((event) => event >= percent); } Stream get playingStream { // if (mkSupportedPlatform) { return _mkPlayer.stream.playing; // } else { // return _justAudio!.playingStream; // } } Stream get shuffledStream { // if (mkSupportedPlatform) { return _mkPlayer.shuffleStream; // } else { // return _justAudio!.shuffleModeEnabledStream; // } } Stream get loopModeStream { // if (mkSupportedPlatform) { return _mkPlayer.stream.playlistMode; // } else { // return _justAudio!.loopModeStream // .map(PlaylistMode.fromLoopMode) // ; // } } Stream get volumeStream { // if (mkSupportedPlatform) { return _mkPlayer.stream.volume.map((event) => event / 100); // } else { // return _justAudio!.volumeStream; // } } Stream get bufferingStream { // if (mkSupportedPlatform) { return Stream.value(false); // } else { // return _justAudio!.playerStateStream // .map( // (event) => // event.processingState == ja.ProcessingState.buffering || // event.processingState == ja.ProcessingState.loading, // ) // ; // } } Stream get playerStateStream { // if (mkSupportedPlatform) { return _mkPlayer.playerStateStream; // } else { // return _justAudio!.playerStateStream // .map(AudioPlaybackState.fromJaPlayerState) // ; // } } Stream get currentIndexChangedStream { // if (mkSupportedPlatform) { return _mkPlayer.indexChangeStream; // } else { // return _justAudio!.sequenceStateStream // .map((event) => event?.currentIndex ?? -1) // ; // } } Stream get activeSourceChangedStream { // if (mkSupportedPlatform) { return _mkPlayer.indexChangeStream .map((event) { return _mkPlayer.state.playlist.medias.elementAtOrNull(event)?.uri; }) .where((event) => event != null) .cast(); // } else { // return _justAudio!.sequenceStateStream // .map((event) { // return (event?.currentSource as ja.UriAudioSource?)?.uri.toString(); // }) // .where((event) => event != null) // .cast(); // } } Stream> get devicesStream => _mkPlayer.stream.audioDevices.asBroadcastStream(); Stream get selectedDeviceStream => _mkPlayer.stream.audioDevice.asBroadcastStream(); Stream get errorStream => _mkPlayer.stream.error; Stream get playlistStream => _mkPlayer.stream.playlist.map((s) { return s; }); }