Linux Seek not working fixed

This commit is contained in:
Kingkor Roy Tirtho 2022-07-01 13:48:25 +06:00
parent a7082d572a
commit 6a05c57dcf
4 changed files with 48 additions and 47 deletions

View File

@ -48,41 +48,25 @@ class PlayerControls extends HookConsumerWidget {
final sliderMax = duration.inSeconds; final sliderMax = duration.inSeconds;
final sliderValue = snapshot.data?.inSeconds ?? 0; final sliderValue = snapshot.data?.inSeconds ?? 0;
// final value = (sliderMax == 0 || sliderValue > sliderMax) final value = (sliderMax == 0 || sliderValue > sliderMax)
// ? 0 ? 0
// : sliderValue / sliderMax; : sliderValue / sliderMax;
final _duration = playback.duration;
final _position = snapshot.data;
final value = (_position != null &&
_duration != null &&
_position.inMilliseconds > 0 &&
_position.inMilliseconds < _duration.inMilliseconds)
? _position.inMilliseconds / _duration.inMilliseconds
: 0.0;
return Column( return Column(
children: [ children: [
Slider.adaptive( Slider.adaptive(
// cannot divide by zero // cannot divide by zero
// there's an edge case for value being bigger // there's an edge case for value being bigger
// than total duration. Keeping it resolved // than total duration. Keeping it resolved
value: value, value: value.toDouble(),
onChanged: (v) async { onChanged: (_) {},
final duration = _duration; onChangeEnd: (value) async {
if (duration == null) { await player.seek(
return; Duration(
} seconds: (value * sliderMax).toInt(),
final position = v * duration.inMilliseconds; ),
await player );
.seek(Duration(milliseconds: position.round()));
}, },
// onChangeEnd: (value) async {
// await player.seek(
// Duration(
// seconds: (value * sliderMax).toInt(),
// ),
// );
// },
activeColor: iconColor, activeColor: iconColor,
), ),
Padding( Padding(

View File

@ -107,8 +107,16 @@ Future<SpotubeTrack> toSpotubeTrack({
"[YouTube Matched Track] ${ytVideo.title} | ${ytVideo.author} - ${ytVideo.url}", "[YouTube Matched Track] ${ytVideo.title} | ${ytVideo.author} - ${ytVideo.url}",
); );
final audioManifest = trackManifest.audioOnly final audioManifest = trackManifest.audioOnly.where((info) {
.where((info) => info.codec.mimeType == "audio/mp4"); final isMp4a = info.codec.mimeType == "audio/mp4";
if (Platform.isLinux) {
return !isMp4a;
} else if (Platform.isMacOS || Platform.isIOS) {
return isMp4a;
} else {
return true;
}
});
final ytUri = (audioQuality == AudioQuality.high final ytUri = (audioQuality == AudioQuality.high
? audioManifest.withHighestBitrate() ? audioManifest.withHighestBitrate()

View File

@ -1,6 +1,10 @@
import 'dart:io';
import 'package:dbus/dbus.dart'; import 'package:dbus/dbus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
final dbusClientProvider = Provider((ref) { final Provider<DBusClient?> dbusClientProvider = Provider<DBusClient?>((ref) {
return DBusClient.session(); if (Platform.isLinux) {
return DBusClient.session();
}
}); });

View File

@ -43,9 +43,9 @@ class Playback extends PersistedChangeNotifier {
LazyBox<CacheTrack>? cacheTrackBox; LazyBox<CacheTrack>? cacheTrackBox;
@protected @protected
final DBusClient dbus; final DBusClient? dbus;
final Media_Player _media_player; Media_Player? _media_player;
late final Player_Interface _mpris; Player_Interface? _mpris;
double volume = 1; double volume = 1;
@ -58,9 +58,7 @@ class Playback extends PersistedChangeNotifier {
Track? currentTrack, Track? currentTrack,
}) : _currentPlaylist = currentPlaylist, }) : _currentPlaylist = currentPlaylist,
_currentTrack = currentTrack, _currentTrack = currentTrack,
_media_player = Media_Player(),
super() { super() {
_mpris = Player_Interface(player: player.core, playback: this);
player.onNextRequest = () { player.onNextRequest = () {
movePlaylistPositionBy(1); movePlaylistPositionBy(1);
}; };
@ -77,16 +75,21 @@ class Playback extends PersistedChangeNotifier {
void _init() async { void _init() async {
// dbus m.p.r.i.s stuff // dbus m.p.r.i.s stuff
try { if (Platform.isLinux) {
final nameStatus = try {
await dbus.requestName("org.mpris.MediaPlayer2.spotube"); _media_player = Media_Player();
if (nameStatus == DBusRequestNameReply.exists) { _mpris = Player_Interface(player: player.core, playback: this);
await dbus.requestName("org.mpris.MediaPlayer2.spotube.instance$pid"); final nameStatus =
await dbus?.requestName("org.mpris.MediaPlayer2.spotube");
if (nameStatus == DBusRequestNameReply.exists) {
await dbus
?.requestName("org.mpris.MediaPlayer2.spotube.instance$pid");
}
await dbus?.registerObject(_media_player!);
await dbus?.registerObject(_mpris!);
} catch (e) {
logger.e("[MPRIS initialization error]", e);
} }
await dbus.registerObject(_media_player);
await dbus.registerObject(_mpris);
} catch (e) {
logger.e("[MPRIS initialization error]", e);
} }
cacheTrackBox = await Hive.openLazyBox<CacheTrack>("track-cache"); cacheTrackBox = await Hive.openLazyBox<CacheTrack>("track-cache");
@ -126,8 +129,10 @@ class Playback extends PersistedChangeNotifier {
_durationStream?.cancel(); _durationStream?.cancel();
_positionStream?.cancel(); _positionStream?.cancel();
cacheTrackBox?.close(); cacheTrackBox?.close();
dbus.unregisterObject(_media_player); if (Platform.isLinux && _media_player != null && _mpris != null) {
dbus.unregisterObject(_mpris); dbus?.unregisterObject(_media_player!);
dbus?.unregisterObject(_mpris!);
}
super.dispose(); super.dispose();
} }