From 9012f560b5915e64807bd20d1b0df574adec56ef Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 4 Sep 2024 23:40:47 +0800 Subject: [PATCH] :bug: Fix netease switch sibling tracks issue --- README.md | 3 +++ .../sourced_track/sources/netease.dart | 14 ++++++------- lib/widgets/player/sibling_tracks.dart | 21 +++++++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f61bdb3..9a393d8 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,9 @@ Their original app is good enough. But I just want to redesign the user interfac - [x] Playing music - [x] Add netease music as source + - [ ] Add bilibili as source + - [ ] Add kuwo music as source + - [ ] Add kugo music as source - [x] Re-design user interface - [x] Simplified UI and UX - [x] Support for large screen device diff --git a/lib/services/sourced_track/sources/netease.dart b/lib/services/sourced_track/sources/netease.dart index 9ef22a8..e7220fc 100755 --- a/lib/services/sourced_track/sources/netease.dart +++ b/lib/services/sourced_track/sources/netease.dart @@ -32,14 +32,14 @@ class NeteaseSourcedTrack extends SourcedTrack { required super.track, }); - static String _getBaseUrl() { + static String getBaseUrl() { final preferences = Get.find().state.value; return preferences.neteaseApiInstance; } - static GetConnect _getClient() { + static GetConnect getClient() { final client = GetConnect(); - client.baseUrl = _getBaseUrl(); + client.baseUrl = getBaseUrl(); client.timeout = const Duration(seconds: 30); return client; } @@ -91,7 +91,7 @@ class NeteaseSourcedTrack extends SourcedTrack { ); } - final client = _getClient(); + final client = getClient(); final resp = await client.get('/song/detail?ids=${cachedSource.sourceId}'); final item = resp.body['songs'][0]; @@ -113,7 +113,7 @@ class NeteaseSourcedTrack extends SourcedTrack { } static SourceMap toSourceMap(dynamic manifest) { - final baseUrl = _getBaseUrl(); + final baseUrl = getBaseUrl(); // Due to netease may provide m4a, mp3 and others, we cannot decide this so mock this data. return SourceMap( @@ -135,7 +135,7 @@ class NeteaseSourcedTrack extends SourcedTrack { }) async { final query = SourcedTrack.getSearchTerm(track); - final client = _getClient(); + final client = getClient(); final resp = await client.get('/search?keywords=${Uri.encodeComponent(query)}'); final results = resp.body['result']['songs']; @@ -181,7 +181,7 @@ class NeteaseSourcedTrack extends SourcedTrack { final newSiblings = siblings.where((s) => s.id != sibling.id).toList() ..insert(0, sourceInfo); - final client = _getClient(); + final client = getClient(); final resp = await client.get('/song/detail?ids=${newSourceInfo.id}'); final item = resp.body['songs'][0]; diff --git a/lib/widgets/player/sibling_tracks.dart b/lib/widgets/player/sibling_tracks.dart index 0e0f246..2e5c4b9 100644 --- a/lib/widgets/player/sibling_tracks.dart +++ b/lib/widgets/player/sibling_tracks.dart @@ -12,6 +12,7 @@ import 'package:rhythm_box/services/server/active_sourced_track.dart'; import 'package:rhythm_box/services/sourced_track/models/source_info.dart'; import 'package:rhythm_box/services/sourced_track/models/video_info.dart'; import 'package:rhythm_box/services/sourced_track/sourced_track.dart'; +import 'package:rhythm_box/services/sourced_track/sources/netease.dart'; import 'package:rhythm_box/services/sourced_track/sources/piped.dart'; import 'package:rhythm_box/services/sourced_track/sources/youtube.dart'; import 'package:rhythm_box/services/artist.dart'; @@ -42,6 +43,7 @@ class _SiblingTracksState extends State { final sourceInfoToLabelMap = { YoutubeSourceInfo: 'YouTube', PipedSourceInfo: 'Piped', + NeteaseSourceInfo: 'Netease', }; List? _subscriptions; @@ -107,6 +109,25 @@ class _SiblingTracksState extends State { ), growable: true, ); + } else if (preferences.audioSource == AudioSource.netease) { + final client = NeteaseSourcedTrack.getClient(); + final resp = await client + .get('/search?keywords=${Uri.encodeComponent(searchTerm)}'); + final searchResults = resp.body['result']['songs'] + .map(NeteaseSourcedTrack.toSiblingType) + .map((x) => x.info) + .toList(); + + final activeSourceInfo = (_activeTrack! as SourcedTrack).sourceInfo; + _siblings = List.from( + searchResults + ..removeWhere((element) => element.id == activeSourceInfo.id) + ..insert( + 0, + activeSourceInfo, + ), + growable: true, + ); } setState(() => _isSearching = false);