Skip next & prev

This commit is contained in:
LittleSheep 2024-08-28 00:04:45 +08:00
parent 7e7df4dc46
commit 5a53fc7268
5 changed files with 30 additions and 6 deletions

View File

@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:math';
import 'package:dismissible_page/dismissible_page.dart';
import 'package:flutter/material.dart';
@ -164,12 +165,12 @@ class _PlayerScreenState extends State<PlayerScreen> {
child: Slider(
secondaryTrackValue: _bufferProgress.abs(),
value: _draggingValue?.abs() ??
(_durationCurrent.inMilliseconds <=
_durationTotal.inMilliseconds
? _durationCurrent.inMilliseconds.toDouble().abs()
: 0),
_durationCurrent.inMilliseconds.toDouble().abs(),
min: 0,
max: _durationTotal.inMilliseconds.abs().toDouble(),
max: max(
_durationTotal.inMilliseconds.abs(),
_durationTotal.inMilliseconds.abs(),
).toDouble(),
onChanged: (value) {
setState(() => _draggingValue = value);
},
@ -198,6 +199,13 @@ class _PlayerScreenState extends State<PlayerScreen> {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
icon: const Icon(Icons.skip_previous),
onPressed: _isFetchingActiveTrack
? null
: audioPlayer.skipToPrevious,
),
const Gap(8),
SizedBox(
width: 56,
height: 56,
@ -219,6 +227,12 @@ class _PlayerScreenState extends State<PlayerScreen> {
_isFetchingActiveTrack ? null : _togglePlayState,
),
),
const Gap(8),
IconButton(
icon: const Icon(Icons.skip_next),
onPressed:
_isFetchingActiveTrack ? null : audioPlayer.skipToNext,
),
],
)
],

View File

@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
import 'package:rhythm_box/platform.dart';
import 'package:rhythm_box/services/local_track.dart';
import 'package:rhythm_box/services/server/server.dart';
import 'package:rhythm_box/widgets/tracks/querying_track_info.dart';
import 'package:spotify/spotify.dart' hide Playlist;
import 'package:rhythm_box/services/audio_player/custom_player.dart';
import 'dart:async';

View File

@ -89,14 +89,17 @@ class RhythmAudioPlayer extends AudioPlayerInterface
int get currentIndex => _mkPlayer.state.playlist.index;
Future<void> skipToNext() async {
Get.find<QueryingTrackInfoProvider>().isQueryingTrackInfo.value = true;
await _mkPlayer.next();
}
Future<void> skipToPrevious() async {
Get.find<QueryingTrackInfoProvider>().isQueryingTrackInfo.value = true;
await _mkPlayer.previous();
}
Future<void> jumpTo(int index) async {
Get.find<QueryingTrackInfoProvider>().isQueryingTrackInfo.value = true;
await _mkPlayer.jump(index);
}

View File

@ -32,7 +32,7 @@ class SourcedTrackProvider extends GetxController {
sourcedTrack.value = await SourcedTrack.fetchFromTrack(track: track);
if (isCurrentTrack) query.isQueryingTrackInfo.value = false;
query.isQueryingTrackInfo.value = false;
return sourcedTrack.value;
}

View File

@ -163,6 +163,12 @@ class _BottomPlayerState extends State<BottomPlayer>
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
icon: const Icon(Icons.skip_next),
onPressed: _isFetchingActiveTrack
? null
: audioPlayer.skipToNext,
),
IconButton.filled(
icon: _isFetchingActiveTrack
? const SizedBox(
height: 20,