fix(windows): local tracks plays but disabled playback controls

This commit is contained in:
Kingkor Roy Tirtho 2024-08-07 21:54:47 +06:00
parent b5f3894983
commit 1c66646798
11 changed files with 35 additions and 53 deletions

View File

@ -37,9 +37,10 @@ class LocalLibraryPage extends HookConsumerWidget {
currentTrack ??= tracks.first;
final isPlaylistPlaying = playlist.containsTracks(tracks);
if (!isPlaylistPlaying) {
var indexWhere = tracks.indexWhere((s) => s.id == currentTrack?.id);
await playback.load(
tracks,
initialIndex: tracks.indexWhere((s) => s.id == currentTrack?.id),
initialIndex: indexWhere,
autoPlay: true,
);
} else if (isPlaylistPlaying &&

View File

@ -1,5 +1,6 @@
import 'dart:math';
import 'package:collection/collection.dart';
import 'package:drift/drift.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:media_kit/media_kit.dart' hide Track;
@ -11,6 +12,7 @@ import 'package:spotube/provider/audio_player/state.dart';
import 'package:spotube/provider/blacklist_provider.dart';
import 'package:spotube/provider/database/database.dart';
import 'package:spotube/provider/discord_provider.dart';
import 'package:spotube/provider/local_tracks/local_tracks_provider.dart';
import 'package:spotube/provider/server/sourced_track.dart';
import 'package:spotube/services/audio_player/audio_player.dart';
@ -283,7 +285,7 @@ class AudioPlayerNotifier extends Notifier<AudioPlayerState> {
// Giving the initial track a boost so MediaKit won't skip
// because of timeout
final intendedActiveTrack = medias.elementAt(initialIndex);
if (intendedActiveTrack is! LocalTrack) {
if (intendedActiveTrack.track is! LocalTrack) {
await ref.read(sourcedTrackProvider(intendedActiveTrack).future);
}
@ -292,7 +294,7 @@ class AudioPlayerNotifier extends Notifier<AudioPlayerState> {
await removeCollections(state.collections);
await audioPlayer.openPlaylist(
medias,
medias.map((s) => s as Media).toList(),
initialIndex: initialIndex,
autoPlay: autoPlay,
);

View File

@ -41,9 +41,16 @@ class SpotubeMedia extends mk.Media {
);
@override
String get uri => track is LocalTrack
? (track as LocalTrack).path
: "http://${kIsWindows ? "localhost" : InternetAddress.anyIPv4.address}:$serverPort/stream/${track.id}";
String get uri {
return switch (track) {
/// [super.uri] must be used instead of [track.path] to prevent wrong
/// path format exceptions in Windows causing [extras] to be null
LocalTrack() => super.uri,
_ =>
"http://${kIsWindows ? "localhost" : InternetAddress.anyIPv4.address}:"
"$serverPort/stream/${track.id}",
};
}
factory SpotubeMedia.fromMedia(mk.Media media) {
final track = media.uri.startsWith("http")
@ -56,20 +63,20 @@ class SpotubeMedia extends mk.Media {
);
}
@override
operator ==(Object other) {
if (other is! SpotubeMedia) return false;
// @override
// operator ==(Object other) {
// if (other is! SpotubeMedia) return false;
final isLocal = track is LocalTrack && other.track is LocalTrack;
return isLocal
? (other.track as LocalTrack).path == (track as LocalTrack).path
: other.track.id == track.id;
}
// final isLocal = track is LocalTrack && other.track is LocalTrack;
// return isLocal
// ? (other.track as LocalTrack).path == (track as LocalTrack).path
// : other.track.id == track.id;
// }
@override
int get hashCode => track is LocalTrack
? (track as LocalTrack).path.hashCode
: track.id.hashCode;
// @override
// int get hashCode => track is LocalTrack
// ? (track as LocalTrack).path.hashCode
// : track.id.hashCode;
}
abstract class AudioPlayerInterface {

View File

@ -149,5 +149,8 @@ mixin SpotubeAudioPlayersStreams on AudioPlayerInterface {
Stream<String> get errorStream => _mkPlayer.stream.error;
Stream<mk.Playlist> get playlistStream => _mkPlayer.stream.playlist;
Stream<mk.Playlist> get playlistStream => _mkPlayer.stream.playlist.map((s){
print("[Stream Playlist]: $s");
return s;
});
}

View File

@ -15,7 +15,6 @@
#include <screen_retriever/screen_retriever_plugin.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
#include <system_theme/system_theme_plugin.h>
#include <system_tray/system_tray_plugin.h>
#include <tray_manager/tray_manager_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>
@ -48,9 +47,6 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) system_theme_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "SystemThemePlugin");
system_theme_plugin_register_with_registrar(system_theme_registrar);
g_autoptr(FlPluginRegistrar) system_tray_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "SystemTrayPlugin");
system_tray_plugin_register_with_registrar(system_tray_registrar);
g_autoptr(FlPluginRegistrar) tray_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "TrayManagerPlugin");
tray_manager_plugin_register_with_registrar(tray_manager_registrar);

View File

@ -12,7 +12,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
sqlite3_flutter_libs
system_theme
system_tray
tray_manager
url_launcher_linux
window_manager

View File

@ -23,7 +23,6 @@ import shared_preferences_foundation
import sqflite
import sqlite3_flutter_libs
import system_theme
import system_tray
import tray_manager
import url_launcher_macos
import window_manager
@ -47,7 +46,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
SystemThemePlugin.register(with: registry.registrar(forPlugin: "SystemThemePlugin"))
SystemTrayPlugin.register(with: registry.registrar(forPlugin: "SystemTrayPlugin"))
TrayManagerPlugin.register(with: registry.registrar(forPlugin: "TrayManagerPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))

View File

@ -717,7 +717,7 @@ packages:
description:
path: "packages/flutter_discord_rpc"
ref: cargokit
resolved-ref: "7ca0bbb786d8ce0e4bf8341b673b6c709ba69146"
resolved-ref: ed8d0d67fae7a23acc9b58c84f01d02abd8d8515
url: "https://github.com/KRTirtho/frb_plugins.git"
source: git
version: "0.1.0+1"
@ -1484,7 +1484,7 @@ packages:
description:
path: "packages/metadata_god"
ref: cargokit
resolved-ref: "7ca0bbb786d8ce0e4bf8341b673b6c709ba69146"
resolved-ref: ed8d0d67fae7a23acc9b58c84f01d02abd8d8515
url: "https://github.com/KRTirtho/frb_plugins.git"
source: git
version: "0.5.3"
@ -1987,7 +1987,7 @@ packages:
description:
path: "packages/smtc_windows"
ref: cargokit
resolved-ref: "7ca0bbb786d8ce0e4bf8341b673b6c709ba69146"
resolved-ref: ed8d0d67fae7a23acc9b58c84f01d02abd8d8515
url: "https://github.com/KRTirtho/frb_plugins.git"
source: git
version: "0.1.3"
@ -2151,15 +2151,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.0.2"
system_tray:
dependency: "direct overridden"
description:
path: "."
ref: dc7ef410d5cfec897edf060c1c4baff69f7c181c
resolved-ref: dc7ef410d5cfec897edf060c1c4baff69f7c181c
url: "https://github.com/antler119/system_tray"
source: git
version: "2.0.2"
term_glyph:
dependency: transitive
description:

View File

@ -164,17 +164,6 @@ dev_dependencies:
dependency_overrides:
uuid: ^4.4.0
system_tray:
# TODO: remove this when flutter_desktop_tools gets updated
# to use [MenuItemBase] instead of [MenuItem]
git:
url: https://github.com/antler119/system_tray
ref: dc7ef410d5cfec897edf060c1c4baff69f7c181c
# media_kit_native_event_loop: # to fix "macro name must be an identifier"
# git:
# url: https://github.com/media-kit/media-kit
# path: media_kit_native_event_loop
# ref: main
flutter:
generate: true

View File

@ -17,7 +17,6 @@
#include <screen_retriever/screen_retriever_plugin.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
#include <system_theme/system_theme_plugin.h>
#include <system_tray/system_tray_plugin.h>
#include <tray_manager/tray_manager_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>
@ -45,8 +44,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("Sqlite3FlutterLibsPlugin"));
SystemThemePluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SystemThemePlugin"));
SystemTrayPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SystemTrayPlugin"));
TrayManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("TrayManagerPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(

View File

@ -14,7 +14,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
sqlite3_flutter_libs
system_theme
system_tray
tray_manager
url_launcher_windows
window_manager