Skip to content

Commit

Permalink
Add some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
WhatDamon committed Feb 5, 2024
1 parent 75b21cf commit 5a024c5
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 7 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img width="50" height="50" align="left" style="float: left; margin: 0 10px 0 0;" alt="Simplay Player Logo" src="https://github.com/WhatDamon/Simplay-Player/blob/main/asset/simplay.png">
<img width="32" height="32" align="left" style="float: left; margin: 0 10px 0 0;" alt="Simplay Player Logo" src="https://github.com/WhatDamon/Simplay-Player/blob/main/asset/simplay.png">

# Simplay Player

Expand All @@ -15,13 +15,13 @@

__Python 3.8 及更高版本__, 推荐 3.10 及更高版本以保障其正常运行

开发前需要先执行...
开发使用前 __*nix系统__ 需要先执行...

~~~Bash
pip install -r requirements.txt
~~~

Windows 需要执行...
__Windows__ 则需要执行...

~~~Bash
pip install -r requirements_win.txt
Expand All @@ -32,8 +32,10 @@ ___注:区分的原因是 `Windows-Toasts` 库只能在 Windows 下生效!___
## TODO

- [x] 基本逻辑
- [x] 吐司通知 (Windows 独占性功能)
- [x] GitHub Actions 自动测试编译工作流 (使用 __Nuitka____Pytest__ 实现)
- [x] 吐司通知 (Windows 独占性功能, 其它系统使用 `SnackBar` 替代)
- [x] 快进与倍速播放
- [x] GitHub Actions 自动测试编译工作流 (使用 __Nuitka__ 实现)
- [ ] 循环播放 (遇到技术性难题, 暂时注释了 `enableOrDisable` 函数, 预留了占位按钮 `playInLoop_btn` 和状态变量 `loopOpen`)
- [ ] 设置 (目前已有占位按钮 `settings_btn`)
- [ ] 歌词显示与滚动 (已预留了歌词路径变量 `lyricFile` 和读取函数 `lyricExistAndRead`)
- [ ] 歌单 (目前已有占位按钮 `audioList_btn`)
Expand All @@ -49,7 +51,7 @@ ___注:区分的原因是 `Windows-Toasts` 库只能在 Windows 下生效!___
以下内容不一定完全, 可能存在更多不在这个列表的 BUG!

- [ ] 读取存在封面的歌曲后再打开无封面歌曲不会替换成占位的 `track.png`
- [ ] `Ctrl` + `H` 快捷键后歌曲进度条无法工作
- [ ] `Ctrl` + `H` 快捷键等操作以后后歌曲进度条无法工作
- [ ] 更换歌曲后可能会有些不是特别影响的报错
- [ ] 打开歌曲后需要连续点击三次播放键才可以进入播放状态

Expand Down
102 changes: 101 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
lyricFile = None
firstPlay = True
playStatus = False
loopOpen = False
progressChanging = False
audioTag = None
audioCoverBase64 = None
Expand Down Expand Up @@ -176,14 +177,59 @@ def playOrPauseMusic(e):
page.title = audioArtistText + " - " + audioTitleText + "- Simplay Player"
page.update()

def audioForward10sec(e):
if playAudio.get_current_position() + 10000 > playAudio.get_duration():
playAudio.seek(playAudio.get_duration())
else:
playAudio.seek(playAudio.get_current_position() + 10000)

def audioBack10sec(e):
if playAudio.get_current_position() - 10000 < 0:
playAudio.seek(0)
else:
playAudio.seek(playAudio.get_current_position() - 10000)

def rateChangeTo05(e):
playAudio.playback_rate = 0.5
playAudio.update()

def rateChangeTo10(e):
playAudio.playback_rate = 1.0
playAudio.update()

def rateChangeTo15(e):
playAudio.playback_rate = 1.5
playAudio.update()

def rateChangeTo20(e):
playAudio.playback_rate = 2.0
playAudio.update()

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("已启用循环播放"))
page.snack_bar.open = True
elif loopOpen == True:
loopOpen = False
page.snack_bar = ft.SnackBar(ft.Text("已禁用循环播放"))
page.snack_bar.open = True
page.update()
"""

def autoStopKeepAudioProgress(e):
global progressChanging
progressChanging = True
Expand Down Expand Up @@ -302,7 +348,49 @@ def balanceMiddle(e):
content = ft.Text("向右移"),
leading = ft.Icon(ft.icons.ARROW_FORWARD_OUTLINED),
on_click = balanceRight
)
]
),
ft.SubmenuButton(
content = ft.Text("进度"),
leading = ft.Icon(ft.icons.TIMER_OUTLINED),
controls = [
ft.MenuItemButton(
content = ft.Text("快进 10s"),
leading = ft.Icon(ft.icons.ARROW_FORWARD_OUTLINED),
on_click = audioForward10sec
),
ft.MenuItemButton(
content = ft.Text("后退 10s"),
leading = ft.Icon(ft.icons.ARROW_BACK_OUTLINED),
on_click = audioBack10sec
)
]
),
ft.SubmenuButton(
content = ft.Text("倍速"),
leading = ft.Icon(ft.icons.SLOW_MOTION_VIDEO_OUTLINED),
controls = [
ft.MenuItemButton(
content = ft.Text("0.5x"),
leading = ft.Icon(ft.icons.ARROW_BACK_OUTLINED),
on_click = rateChangeTo05
),
ft.MenuItemButton(
content = ft.Text("1x"),
leading = ft.Icon(ft.icons.STOP_OUTLINED),
on_click = rateChangeTo10
),
ft.MenuItemButton(
content = ft.Text("1.5x"),
leading = ft.Icon(ft.icons.ARROW_FORWARD_OUTLINED),
on_click = rateChangeTo15
),
ft.MenuItemButton(
content = ft.Text("2x"),
leading = ft.Icon(ft.icons.ROCKET_LAUNCH_OUTLINED),
on_click = rateChangeTo20
)
]
),
ft.MenuItemButton(
Expand Down Expand Up @@ -355,6 +443,13 @@ def balanceMiddle(e):
on_click = playOrPauseMusic
)

playInLoop = ft.IconButton(
icon = ft.icons.LOOP_OUTLINED,
tooltip = "循环播放",
icon_size = 20,
# on_click = enableOrDisableLoop
)

volume_btn = ft.IconButton(
icon = ft.icons.VOLUME_UP_OUTLINED,
tooltip = "音量",
Expand All @@ -374,22 +469,25 @@ def balanceMiddle(e):
audioList_btn = ft.IconButton(
icon = ft.icons.LIBRARY_MUSIC_OUTLINED,
tooltip = "歌单",
icon_size = 20,
)

audioInfo_btn = ft.IconButton(
icon = ft.icons.INFO_OUTLINE,
tooltip = "歌曲信息",
icon_size = 20,
on_click = openAudioInfoDlg
)

settings_btn = ft.IconButton(
icon = ft.icons.SETTINGS_OUTLINED,
tooltip = "设置",
icon_size = 20,
)

lyric_text = ft.Text(size = 20)

playbackCtrl_row = ft.Row(controls = [playPause_btn, volume_btn, volume_panel])
playbackCtrl_row = ft.Row(controls = [playPause_btn, playInLoop, volume_btn, volume_panel])
moreBtns_row = ft.Row(controls = [audioList_btn, audioInfo_btn, settings_btn])
btns_row = ft.Row(controls = [playbackCtrl_row, moreBtns_row], alignment = ft.MainAxisAlignment.SPACE_BETWEEN)

Expand All @@ -399,6 +497,8 @@ def balanceMiddle(e):
detectOS()
if currentOS == 'wsl':
print("发现您正在使用 WSL, 实际上, 我们更推荐您直接使用 Windows 版本以避免潜在的 BUG")
if currentOS == 'cygwin':
print("发现您正在使用 Cygwin, 实际上, 我们更推荐您直接使用 Windows 版本以避免潜在的 BUG")
if currentOS == "windows":
from windows_toasts import Toast, ToastDisplayImage, WindowsToaster
else:
Expand Down

0 comments on commit 5a024c5

Please sign in to comment.