mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
Update audio_player_impl.dart
This commit is contained in:
parent
cee65b5f2f
commit
8b6cc11486
@ -1,45 +1,28 @@
|
|||||||
part of 'audio_player.dart';
|
|
||||||
|
|
||||||
final audioPlayer = SpotubeAudioPlayer();
|
final audioPlayer = SpotubeAudioPlayer();
|
||||||
|
|
||||||
class SpotubeAudioPlayer extends AudioPlayerInterface
|
class SpotubeAudioPlayer extends AudioPlayerInterface with SpotubeAudioPlayersStreams {
|
||||||
with SpotubeAudioPlayersStreams {
|
// Playback control methods
|
||||||
Future<void> pause() async {
|
Future<void> pause() async => await player.pause();
|
||||||
await _mkPlayer.pause();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> resume() async {
|
Future<void> resume() async => await player.play();
|
||||||
await _mkPlayer.play();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> stop() async {
|
Future<void> stop() async => await player.stop();
|
||||||
await _mkPlayer.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> seek(Duration position) async {
|
Future<void> seek(Duration position) async => await player.seek(position);
|
||||||
await _mkPlayer.seek(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Volume is between 0 and 1
|
/// Set volume between 0 and 1
|
||||||
Future<void> setVolume(double volume) async {
|
Future<void> setVolume(double volume) async {
|
||||||
assert(volume >= 0 && volume <= 1);
|
assert(volume >= 0 && volume <= 1);
|
||||||
await _mkPlayer.setVolume(volume * 100);
|
await player.setVolume(volume * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setSpeed(double speed) async {
|
Future<void> setSpeed(double speed) async => await player.setRate(speed);
|
||||||
await _mkPlayer.setRate(speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setAudioDevice(mk.AudioDevice device) async {
|
Future<void> setAudioDevice(mk.AudioDevice device) async => await player.setAudioDevice(device);
|
||||||
await _mkPlayer.setAudioDevice(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> dispose() async {
|
Future<void> dispose() async => await player.dispose();
|
||||||
await _mkPlayer.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Playlist related
|
|
||||||
|
|
||||||
|
// Playlist control methods
|
||||||
Future<void> openPlaylist(
|
Future<void> openPlaylist(
|
||||||
List<mk.Media> tracks, {
|
List<mk.Media> tracks, {
|
||||||
bool autoPlay = true,
|
bool autoPlay = true,
|
||||||
@ -47,88 +30,59 @@ class SpotubeAudioPlayer extends AudioPlayerInterface
|
|||||||
}) async {
|
}) async {
|
||||||
assert(tracks.isNotEmpty);
|
assert(tracks.isNotEmpty);
|
||||||
assert(initialIndex <= tracks.length - 1);
|
assert(initialIndex <= tracks.length - 1);
|
||||||
await _mkPlayer.open(
|
|
||||||
|
await player.open(
|
||||||
mk.Playlist(tracks, index: initialIndex),
|
mk.Playlist(tracks, index: initialIndex),
|
||||||
play: autoPlay,
|
play: autoPlay,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> get sources {
|
// Helper methods for playlist sources
|
||||||
return _mkPlayer.state.playlist.medias.map((e) => e.uri).toList();
|
List<String> get sources => player.state.playlist.medias.map((e) => e.uri).toList();
|
||||||
}
|
|
||||||
|
|
||||||
String? get currentSource {
|
String? get currentSource {
|
||||||
if (_mkPlayer.state.playlist.index == -1) return null;
|
final index = player.state.playlist.index;
|
||||||
return _mkPlayer.state.playlist.medias
|
if (index == -1) return null;
|
||||||
.elementAtOrNull(_mkPlayer.state.playlist.index)
|
return player.state.playlist.medias.elementAtOrNull(index)?.uri;
|
||||||
?.uri;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String? get nextSource {
|
String? get nextSource {
|
||||||
if (loopMode == PlaylistMode.loop &&
|
final isLastTrack = player.state.playlist.index == player.state.playlist.medias.length - 1;
|
||||||
_mkPlayer.state.playlist.index ==
|
if (loopMode == PlaylistMode.loop && isLastTrack) return sources.first;
|
||||||
_mkPlayer.state.playlist.medias.length - 1) {
|
|
||||||
return sources.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _mkPlayer.state.playlist.medias
|
return player.state.playlist.medias.elementAtOrNull(player.state.playlist.index + 1)?.uri;
|
||||||
.elementAtOrNull(_mkPlayer.state.playlist.index + 1)
|
|
||||||
?.uri;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String? get previousSource {
|
String? get previousSource {
|
||||||
if (loopMode == PlaylistMode.loop && _mkPlayer.state.playlist.index == 0) {
|
if (loopMode == PlaylistMode.loop && player.state.playlist.index == 0) return sources.last;
|
||||||
return sources.last;
|
|
||||||
|
return player.state.playlist.medias.elementAtOrNull(player.state.playlist.index - 1)?.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _mkPlayer.state.playlist.medias
|
int get currentIndex => player.state.playlist.index;
|
||||||
.elementAtOrNull(_mkPlayer.state.playlist.index - 1)
|
|
||||||
?.uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get currentIndex => _mkPlayer.state.playlist.index;
|
// Playlist navigation methods
|
||||||
|
Future<void> skipToNext() async => await player.next();
|
||||||
|
|
||||||
Future<void> skipToNext() async {
|
Future<void> skipToPrevious() async => await player.previous();
|
||||||
await _mkPlayer.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> skipToPrevious() async {
|
Future<void> jumpTo(int index) async => await player.jump(index);
|
||||||
await _mkPlayer.previous();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> jumpTo(int index) async {
|
// Playlist management methods
|
||||||
await _mkPlayer.jump(index);
|
Future<void> addTrack(mk.Media media) async => await player.add(media);
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> addTrack(mk.Media media) async {
|
Future<void> addTrackAt(mk.Media media, int index) async => await player.insert(index, media);
|
||||||
await _mkPlayer.add(media);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> addTrackAt(mk.Media media, int index) async {
|
Future<void> removeTrack(int index) async => await player.remove(index);
|
||||||
await _mkPlayer.insert(index, media);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> removeTrack(int index) async {
|
Future<void> moveTrack(int from, int to) async => await player.move(from, to);
|
||||||
await _mkPlayer.remove(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> moveTrack(int from, int to) async {
|
Future<void> clearPlaylist() async => await player.stop();
|
||||||
await _mkPlayer.move(from, to);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> clearPlaylist() async {
|
// Shuffle and loop mode control
|
||||||
_mkPlayer.stop();
|
Future<void> setShuffle(bool shuffle) async => await player.setShuffle(shuffle);
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setShuffle(bool shuffle) async {
|
Future<void> setLoopMode(PlaylistMode loop) async => await player.setPlaylistMode(loop);
|
||||||
await _mkPlayer.setShuffle(shuffle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setLoopMode(PlaylistMode loop) async {
|
Future<void> setAudioNormalization(bool normalize) async => await player.setAudioNormalization(normalize);
|
||||||
await _mkPlayer.setPlaylistMode(loop);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setAudioNormalization(bool normalize) async {
|
|
||||||
await _mkPlayer.setAudioNormalization(normalize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user