From c50b2f547fc5d6e79c506f1d1f8086eb2ef39c33 Mon Sep 17 00:00:00 2001 From: Damon Lu <59256766+WhatDamon@users.noreply.github.com> Date: Fri, 9 Feb 2024 18:46:03 +0800 Subject: [PATCH] Functional --- .github/workflows/build.yml | 1 + .github/workflows/buildwin.yml | 3 +- README.md | 2 +- main.py | 55 ++++++++++++++++++---------------- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f30e54..34c54c4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,6 +41,7 @@ jobs: with: nuitka-version: main script-name: main.py + onefile: true standalone: true disable-console: true diff --git a/.github/workflows/buildwin.yml b/.github/workflows/buildwin.yml index f8cdc4b..c0d7055 100644 --- a/.github/workflows/buildwin.yml +++ b/.github/workflows/buildwin.yml @@ -41,6 +41,7 @@ jobs: with: nuitka-version: main script-name: main.py + onefile: true standalone: true disable-console: true windows-icon-from-ico: ./asset/spicon.ico @@ -50,4 +51,4 @@ jobs: with: name: ${{ runner.os }} Build path: | - build/* \ No newline at end of file + build/*.exe \ No newline at end of file diff --git a/README.md b/README.md index 55debef..9aa2db3 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ ___注:区分的原因是 `Windows-Toasts` 库只能在 Windows 下生效!___ - [x] GitHub Actions 自动测试编译工作流 (使用 __Nuitka__ 实现, 详见[本项目 Actions](https://github.com/WhatDamon/Simplay-Player/actions)) - [x] 多语言支持 (基本, 目前只有美式英语 `en_US` 和简体中文 `zh_CN`, 若要贡献翻译请到 `i18n` 目录) - [x] 日志输出 (注: 会产生大量日志信息) -- [ ] 循环播放 (遇到技术性难题, 暂时注释了 `enableOrDisable` 函数 (函数临时被注释), 预留了占位按钮 `playInLoop_btn` (组件已隐藏) 和状态变量 `loopOpen`) +- [x] 循环播放 - [ ] 设置 (目前已有占位按钮 `settings_btn`, 并隐藏) - [ ] 歌词显示与滚动 (已预留了歌词路径变量 `lyricFile` 和读取函数 `lyricExistAndRead`(函数临时被注释)) - [ ] 歌单 (施工中) diff --git a/main.py b/main.py index 28bfd81..9a0ecbc 100644 --- a/main.py +++ b/main.py @@ -21,6 +21,7 @@ audioInfo = None audioTitleText = None audioArtistText = None +audioAlbumText = None currentOS = None logging.info("Variable initialization complete") @@ -140,24 +141,32 @@ def audioInfoUpdate(): logging.info("Placeholder cover loaded") audioCover.update() logging.info("audioCover updated") - global audioTitleText, audioArtistText + global audioTitleText, audioArtistText, audioAlbumText if audioTag.title != None: audioTitleText = audioTag.title - logging.info("Set audio title") + logging.info("Set audio title: " + audioTitleText) else: audioTitleText = lang.mainMenu["unknownMusic"] logging.info("Unknown audio title") if audioTag.artist != None: audioArtistText = audioTag.artist - logging.info("Set audio artist") + logging.info("Set audio artist: " + audioArtistText) else: audioArtistText = lang.mainMenu["unknownArtist"] logging.info("Unknown audio artist") + if audioTag.album != None: + audioAlbumText = audioTag.album + logging.info("Find audio album and loaded: " + audioAlbumText) global audioInfo audioInfo = "Album: " + str(audioTag.album) + "\nAlbumist: " + str(audioTag.albumartist) + "\nArtist: " + str(audioTag.artist) + "\nAudio Offset: " + str(audioTag.audio_offset) + "\nBitrate: " + str(audioTag.bitrate) + "\nBitdepth: " + str(audioTag.bitdepth) + "\nChannels: " + str(audioTag.channels) + "\nComment: " + str(audioTag.comment)+ "\nComposer: " + str(audioTag.composer) + "\nDisc: " + str(audioTag.disc) + "\nDisc Total: " + str(audioTag.disc_total) + "\nDuration: " + str(audioTag.duration) + "\nFilesize: " + str(audioTag.filesize) + "\nGenre: " + str(audioTag.genre) + "\nSamplerate: " + str(audioTag.samplerate) + "\nTitle: " + str(audioTag.title) + "\nTrack: " + str(audioTag.track) + "\nTrack Total: " + str(audioTag.track_total) + "\nYear: " + str(audioTag.year) logging.info("Set audio info") audioTitle.value = audioTitleText - audioArtist.value = audioArtistText + if audioAlbumText == None: + audioArtistAndAlbum.value = audioArtistText + logging.info("No album text loaded") + else: + audioArtistAndAlbum.value = audioArtistText + " · " + audioAlbumText + logging.info("Album text loaded") logging.info("Load audio info to interface") page.update() logging.info("Page updated") @@ -298,28 +307,25 @@ def rateChangeTo20(e): def autoKeepAudioProgress(e): if progressChanging == False: audioProgressBar.value = playAudio.get_current_position() / playAudio.get_duration() * 1000 - global loopOpen - if playAudio.get_current_position() == playAudio.get_duration() and loopOpen == True: - playAudio.seek(0) currentLength = secondConvert(playAudio.get_current_position() // 1000) totalLength = secondConvert(playAudio.get_duration() // 1000) audioProgressStatus.value = currentLength + "/" + totalLength page.update() - """ def enableOrDisableLoop(e): global loopOpen if loopOpen == False: loopOpen = True - page.snack_bar = ft.SnackBar(ft.Text(value = lang.mainMenu["enableLoop"])) - page.snack_bar.open = True + playAudio.release_mode = ft.audio.ReleaseMode.LOOP + playInLoop_btn.icon = ft.icons.STOP_CIRCLE_OUTLINED + logging.info("Loop enabled") elif loopOpen == True: loopOpen = False - print(playAudio.release_mode) - # playAudio.release_mode = ReleaseMode.LOOP + playAudio.release_mode = ft.audio.ReleaseMode.RELEASE + playInLoop_btn.icon = ft.icons.LOOP_OUTLINED + logging.info("Loop disabled") page.update() logging.info("Page updated") - """ def autoStopKeepAudioProgress(e): global progressChanging @@ -575,9 +581,9 @@ def balanceMiddle(e): audioCover = ft.Image(src = './asset/track.png', width = 128, height = 128, border_radius = 5) audioTitle = ft.Text(audioTitleText, weight = ft.FontWeight.BOLD, size = 25, overflow = ft.TextOverflow.ELLIPSIS) - audioArtist = ft.Text(audioArtistText, size = 18, opacity = 90) + audioArtistAndAlbum = ft.Text(audioArtistText, size = 18, opacity = 90) audioProgressStatus = ft.Text("00:00/00:00", size = 15, opacity = 90) - audioDetail = ft.Column(controls = [audioTitle, audioArtist, audioProgressStatus]) + audioDetail = ft.Column(controls = [audioTitle, audioArtistAndAlbum, audioProgressStatus]) audioBasicInfo = ft.Row(controls = [audioCover, audioDetail]) audioProgressBar = ft.Slider(min = 0, max = 1000, tooltip = lang.tooltips["audioPosition"], on_change_start = autoStopKeepAudioProgress, on_change_end = progressCtrl) @@ -589,14 +595,6 @@ def balanceMiddle(e): on_click = playOrPauseMusic ) - playInLoop = ft.IconButton( - icon = ft.icons.LOOP_OUTLINED, - tooltip = lang.tooltips["playInLoop"], - icon_size = 20, - visible = False - # on_click = enableOrDisableLoop - ) - volume_btn = ft.IconButton( icon = ft.icons.VOLUME_UP_OUTLINED, tooltip = lang.tooltips["volume"], @@ -612,6 +610,13 @@ def balanceMiddle(e): height = 46, width = 200 ) + + playInLoop_btn = ft.IconButton( + icon = ft.icons.LOOP_OUTLINED, + tooltip = lang.tooltips["playInLoop"], + icon_size = 20, + on_click = enableOrDisableLoop + ) audioList_btn = ft.IconButton( icon = ft.icons.LIBRARY_MUSIC_OUTLINED, @@ -663,8 +668,8 @@ def balanceMiddle(e): lyric_text = ft.Text(size = 20) - playbackCtrl_row = ft.Row(controls = [playPause_btn, playInLoop, volume_btn, volume_panel]) - moreBtns_row = ft.Row(controls = [audioList_btn, audioInfo_btn, settings_btn]) + playbackCtrl_row = ft.Row(controls = [playPause_btn, volume_btn, volume_panel]) + moreBtns_row = ft.Row(controls = [playInLoop_btn, audioList_btn, audioInfo_btn, settings_btn]) btns_row = ft.Row(controls = [playbackCtrl_row, moreBtns_row], alignment = ft.MainAxisAlignment.SPACE_BETWEEN) page.overlay.append(audioList_menu)