Skip to content

Commit

Permalink
[Work] sync
Browse files Browse the repository at this point in the history
  • Loading branch information
canxin121 committed Oct 5, 2024
1 parent 7970b07 commit 859f193
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 45 deletions.
2 changes: 1 addition & 1 deletion lib/mobile/comps/play_display_comp/quality_time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class QualityTimeState extends State<QualityTime> {
return Badge(
isDarkMode: true,
label: globalAudioHandler
.playingMusic.value?.playInfo?.quality.summary ??
.playingMusic.value?.playinfo?.quality.summary ??
"Quality",
);
}),
Expand Down
24 changes: 8 additions & 16 deletions lib/mobile/pages/play_display_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ class SongDisplayPageState extends State<SongDisplayPage> {

@override
Widget build(BuildContext context) {
const bool isDarkMode = true;
const animateBackgroundColor = CupertinoColors.white;
final isDarkMode =
MediaQuery.of(context).platformBrightness == Brightness.dark;

final Color backgroundColor =
isDarkMode ? CupertinoColors.black : CupertinoColors.white;
const backgroundColor1 = Color.fromARGB(255, 56, 56, 56);
const backgroundColor2 = Color.fromARGB(255, 31, 31, 31);

const textColor = CupertinoColors.white;

double screenWidth = MediaQuery.of(context).size.width;
Expand All @@ -76,12 +78,10 @@ class SongDisplayPageState extends State<SongDisplayPage> {
break;
case PageState.list:
topWidgets = <Widget>[
// 占据70高度
const PlayingMusicCard(
height: 70,
picPadding: EdgeInsets.only(left: 20),
),
// 占据20高度
Container(
padding:
const EdgeInsets.only(left: 20, top: 20, bottom: 10, right: 20),
Expand Down Expand Up @@ -111,7 +111,6 @@ class SongDisplayPageState extends State<SongDisplayPage> {
],
),
),
// 应当占据剩下的所有高度
MusicListComp(
maxHeight: screenHeight * 0.87 - 300,
),
Expand All @@ -123,10 +122,9 @@ class SongDisplayPageState extends State<SongDisplayPage> {
height: 70,
picPadding: EdgeInsets.only(left: 20),
),
// 应当占据剩下的空间
LyricDisplay(
maxHeight: screenHeight * 0.87 - 240,
isDarkMode: isDarkMode,
isDarkMode: true,
)
];
break;
Expand All @@ -135,7 +133,7 @@ class SongDisplayPageState extends State<SongDisplayPage> {
return DismissiblePage(
isFullScreen: true,
direction: DismissiblePageDismissDirection.down,
backgroundColor: animateBackgroundColor,
backgroundColor: backgroundColor,
onDismissed: () => Navigator.of(context).pop(),
child: Container(
clipBehavior: Clip.antiAliasWithSaveLayer,
Expand All @@ -154,28 +152,24 @@ class SongDisplayPageState extends State<SongDisplayPage> {
...topWidgets
],
),
// 固定在页面底部的内容,共占据约 140 + screenHeight * 0.2 的高度
Positioned(
bottom: 0, // 确保它固定在底部
bottom: 0,
left: 0,
right: 0,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
// main界面时占据36的高度
if (pageState == PageState.main)
const MusicInfo(
titleHeight: 20,
artistHeight: 16,
padding: EdgeInsets.only(left: 40, right: 40),
),
// 占据约35的高度
const ProgressSlider(
padding: EdgeInsets.only(
top: 10, bottom: 10, left: 20, right: 20),
isDarkMode: true,
),
// 占据 12 高度
const QualityTime(
fontHeight: 12,
padding: 35,
Expand All @@ -192,8 +186,6 @@ class SongDisplayPageState extends State<SongDisplayPage> {
padding: EdgeInsets.only(left: 20, right: 20),
isDarkMode: true,
),
// if (!Platform.isIOS) const VolumeSlider(),
// 占据 55 的高度
BottomButton(
onList: onListBotton,
onLyric: onLyricBotton,
Expand Down
5 changes: 3 additions & 2 deletions lib/types/audio_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class AudioHandler {
if (targetMusicContainer == null) return;

playingMusic.value = targetMusicContainer;

playingMusic.refresh();
try {
if (!await targetMusicContainer!.updateAll(quality)) {
globalTalker.info(
Expand All @@ -149,6 +149,7 @@ class AudioHandler {
"[AudioHanlder.lazyLoadMusic] LazyLoad Music Succeed: ${targetMusicContainer!.musicAggregator.name}");
} catch (e) {
playingMusic.value = null;
playingMusic.refresh();
globalTalker.error("[AudioHandler.tryLazyLoadMusic] Unknown Error: $e");
}
}
Expand Down Expand Up @@ -206,7 +207,7 @@ class AudioHandler {

await _lazyLoadMusic(player.currentIndex!,
quality: quality, force: true);

playingMusic.refresh();
await seek(position);
}
} catch (e) {
Expand Down
49 changes: 25 additions & 24 deletions lib/types/music_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MusicContainer {
late int currentMusicIndex;
late AudioSource audioSource;

PlayInfo? playInfo;
PlayInfo? playinfo;
String? lyric;
List<MusicServer> usedServers = [];
DateTime lastUpdateDateTime = DateTime(1999);
Expand Down Expand Up @@ -55,17 +55,18 @@ class MusicContainer {
Future<bool> updateAll([Quality? quality]) async {
await getUpdatePlayAndLyricInfoAutoChangeSource(quality);
await _updateAudioSource();
return playInfo != null;
return playinfo != null;
}

/// safe
Future<PlayInfo?> getUpdatePlayAndLyricInfoAutoChangeSource(
[Quality? quality]) async {
while (true) {
playInfo ??= await getUpdatePlayInfoAndLyric(quality);

if (playInfo != null) {
return playInfo;
var newPlayinfo = await getUpdatePlayInfoAndLyric(quality);
// playInfo ??= await getUpdatePlayInfoAndLyric(quality);
playinfo = newPlayinfo;
if (playinfo != null) {
return playinfo;
} else {
bool changed = await changeMusicServer();
if (!changed) {
Expand All @@ -90,19 +91,19 @@ class MusicContainer {
name: musicAggregator.name,
artists: musicAggregator.artist,
documentFolder: globalDocumentPath);
playInfo = musicCache?.$1;
playinfo = musicCache?.$1;
lyric = musicCache?.$2;
try {
lyric ??= await currentMusic.getLyric();
} catch (e) {
LogToast.error("在线获取歌词失败", "在线获取歌词失败: ${currentMusic.name} $e",
"[getUpdateMusicPlayInfo] Failed to get lyric: $e");
}
if (playInfo != null) {
if (playinfo != null) {
globalTalker
.info("[getUpdateMusicPlayInfo] 使用缓存歌曲: ${currentMusic.name}");
setUpdated();
return playInfo!;
return playinfo!;
}
// ignore: empty_catches
} catch (e) {}
Expand All @@ -113,10 +114,10 @@ class MusicContainer {
return null;
}

playInfo = await globalExternalApiEvaler!.getMusicPlayInfo(currentMusic,
playinfo = await globalExternalApiEvaler!.getMusicPlayInfo(currentMusic,
selectedQuality ?? autoPickQuality(currentMusic.qualities));

if (playInfo == null) {
if (playinfo == null) {
globalTalker.error(
"[getUpdateMusicPlayInfo] 第三方音乐源无法获取到playinfo: [${currentMusic.server}]${currentMusic.name}");
return null;
Expand All @@ -125,7 +126,7 @@ class MusicContainer {
globalTalker.info(
"[getUpdateMusicPlayInfo] 使用第三方Api请求获取playinfo: [${currentMusic.server}]${currentMusic.name}");
setUpdated();
return playInfo;
return playinfo;
}

/// safe
Expand All @@ -146,33 +147,33 @@ class MusicContainer {

/// safe
Future<bool> _updateAudioSource() async {
if (playInfo != null) {
if (playInfo!.uri.contains("http")) {
if (playinfo != null) {
if (playinfo!.uri.contains("http")) {
if ((Platform.isIOS || Platform.isMacOS) &&
((playInfo!.quality.format != null &&
playInfo!.quality.format!.contains("flac")) ||
(playInfo!.quality.summary.contains("flac")))) {
audioSource = ProgressiveAudioSource(Uri.parse(playInfo!.uri),
((playinfo!.quality.format != null &&
playinfo!.quality.format!.contains("flac")) ||
(playinfo!.quality.summary.contains("flac")))) {
audioSource = ProgressiveAudioSource(Uri.parse(playinfo!.uri),
tag: _toMediaItem(),
options: const ProgressiveAudioSourceOptions(
darwinAssetOptions: DarwinAssetOptions(
preferPreciseDurationAndTiming: true)));
} else {
audioSource =
AudioSource.uri(Uri.parse(playInfo!.uri), tag: _toMediaItem());
AudioSource.uri(Uri.parse(playinfo!.uri), tag: _toMediaItem());
}
} else {
if ((Platform.isIOS || Platform.isMacOS) &&
((playInfo!.quality.format != null &&
playInfo!.quality.format!.contains("flac")) ||
(playInfo!.quality.summary.contains("flac")))) {
audioSource = ProgressiveAudioSource(Uri.file(playInfo!.uri),
((playinfo!.quality.format != null &&
playinfo!.quality.format!.contains("flac")) ||
(playinfo!.quality.summary.contains("flac")))) {
audioSource = ProgressiveAudioSource(Uri.file(playinfo!.uri),
tag: _toMediaItem(),
options: const ProgressiveAudioSourceOptions(
darwinAssetOptions: DarwinAssetOptions(
preferPreciseDurationAndTiming: true)));
} else {
audioSource = AudioSource.file(playInfo!.uri, tag: _toMediaItem());
audioSource = AudioSource.file(playinfo!.uri, tag: _toMediaItem());
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/utils/music_api_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ Future<void> delMusicAggregatorCache(MusicAggregator musicAggregator,
Future<void> cacheMusicContainer(MusicContainer musicContainer) async {
try {
var success = await musicContainer.updateAll();
if (!success || musicContainer.playInfo == null) {
if (!success || musicContainer.playinfo == null) {
return;
}
await rust_api_music_cache.cacheMusic(
name: musicContainer.musicAggregator.name,
artists: musicContainer.musicAggregator.artist,
playinfo: musicContainer.playInfo!,
playinfo: musicContainer.playinfo!,
lyric: musicContainer.lyric,
documentFolder: globalDocumentPath);

Expand Down

0 comments on commit 859f193

Please sign in to comment.