part of 'audio_player.dart'; final audioPlayer = RhythmAudioPlayer(); class RhythmAudioPlayer extends AudioPlayerInterface with RhythmAudioPlayersStreams { Future pause() async { await _mkPlayer.pause(); } Future resume() async { await _mkPlayer.play(); } Future stop() async { await _mkPlayer.stop(); } Future seek(Duration position) async { await _mkPlayer.seek(position); } /// Volume is between 0 and 1 Future setVolume(double volume) async { assert(volume >= 0 && volume <= 1); await _mkPlayer.setVolume(volume * 100); } Future setSpeed(double speed) async { await _mkPlayer.setRate(speed); } Future setAudioDevice(mk.AudioDevice device) async { await _mkPlayer.setAudioDevice(device); } Future dispose() async { await _mkPlayer.dispose(); } // Playlist related Future openPlaylist( List tracks, { bool autoPlay = true, int initialIndex = 0, }) async { assert(tracks.isNotEmpty); assert(initialIndex <= tracks.length - 1); await _mkPlayer.open( mk.Playlist(tracks, index: initialIndex), play: autoPlay, ); } List get sources { return _mkPlayer.state.playlist.medias.map((e) => e.uri).toList(); } String? get currentSource { if (_mkPlayer.state.playlist.index == -1) return null; return _mkPlayer.state.playlist.medias .elementAtOrNull(_mkPlayer.state.playlist.index) ?.uri; } String? get nextSource { if (loopMode == PlaylistMode.loop && _mkPlayer.state.playlist.index == _mkPlayer.state.playlist.medias.length - 1) { return sources.first; } return _mkPlayer.state.playlist.medias .elementAtOrNull(_mkPlayer.state.playlist.index + 1) ?.uri; } String? get previousSource { if (loopMode == PlaylistMode.loop && _mkPlayer.state.playlist.index == 0) { return sources.last; } return _mkPlayer.state.playlist.medias .elementAtOrNull(_mkPlayer.state.playlist.index - 1) ?.uri; } int get currentIndex => _mkPlayer.state.playlist.index; Future skipToNext() async { Get.find().isQueryingTrackInfo.value = true; await _mkPlayer.next(); } Future skipToPrevious() async { Get.find().isQueryingTrackInfo.value = true; await _mkPlayer.previous(); } Future jumpTo(int index) async { Get.find().isQueryingTrackInfo.value = true; await _mkPlayer.jump(index); } Future addTrack(mk.Media media) async { await _mkPlayer.add(media); } Future addTrackAt(mk.Media media, int index) async { await _mkPlayer.insert(index, media); } Future removeTrack(int index) async { await _mkPlayer.remove(index); } Future moveTrack(int from, int to) async { await _mkPlayer.move(from, to); } Future clearPlaylist() async { _mkPlayer.stop(); } Future setShuffle(bool shuffle) async { await _mkPlayer.setShuffle(shuffle); } Future setLoopMode(PlaylistMode loop) async { await _mkPlayer.setPlaylistMode(loop); } Future setAudioNormalization(bool normalize) async { await _mkPlayer.setAudioNormalization(normalize); } }