Skip to content

Commit

Permalink
Bugfix and something new
Browse files Browse the repository at this point in the history
  • Loading branch information
WhatDamon committed Feb 23, 2024
1 parent 20acadd commit b8966e3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
2 changes: 2 additions & 0 deletions i18n/en_US.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
"purple": "Purple",
"play": "Play",
"immediatelyPlay": "Play the song immediately after loading",
"defaultLoop": "Default looped playback",
"defaultVolume": "Default Volume: ",
"lyrics": "Lyrics",
"lyricsDefaultVis": "Lyrics display by default",
"webMusic": "Online music",
Expand Down
2 changes: 2 additions & 0 deletions i18n/zh_CN.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
"purple": "紫色",
"play": "播放",
"immediatelyPlay": "加载歌曲后立即播放",
"defaultLoop": "默认循环播放",
"defaultVolume": "默认音量: ",
"lyrics": "歌词",
"lyricsDefaultVis": "歌词默认显示",
"webMusic": "在线歌曲",
Expand Down
16 changes: 15 additions & 1 deletion lib/smtc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import winsdk.windows.media.playback as mediaPlayback
import winsdk.windows.media as media
import winsdk.windows.media.playback as playBack

# https://learn.microsoft.com/zh-cn/windows/uwp/audio-video-camera/integrate-with-systemmediatransportcontrols
props = playBack.MediaItemDisplayProperties
props.type = media.MediaPlaybackType.MUSIC
props.music_properties.title = "Song title"
props.music_properties.artist = "Song artist"
props.music_properties.genres.append("Polka")
playBack.MediaPlaybackItem.apply_display_properties(props)

# https://learn.microsoft.com/zh-cn/windows/uwp/audio-video-camera/system-media-transport-controls

smtc = media.SystemMediaTransportControls
smtc.is_enabled = True

if smtc.is_enabled == True:
pass


# 有点没头绪怎么处理
16 changes: 14 additions & 2 deletions lib/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
audioInfo = None
audioTitleText = None
audioArtistText = None
audioState = None

log_init.logging.info("Variable initialization complete at work.py")

Expand Down Expand Up @@ -172,6 +173,12 @@ def playOrPauseMusic(e): # 歌曲播放/暂停
else:
log_init.logging.warning("No audio file")

def resetPlay():
global playStatus, playPause_btn_icon, page_title
playStatus = False
page_title = audioArtistText + " - " + audioTitleText + " | Simplay Player"
playPause_btn_icon = ft.icons.PLAY_CIRCLE_FILL_OUTLINED

def audioForward10sec(e):
if playAudio.get_current_position() + 10000 > playAudio.get_duration():
log_init.logging.warning("More than the total length of the song")
Expand Down Expand Up @@ -284,11 +291,16 @@ def balanceMiddle(e):
playAudio.update()
log_init.logging.info("playAudio updated")

def stateSet(e):
global audioState
audioState = e.data
log_init.logging.info("State changed:" + e.data)

playAudio = ft.Audio(
autoplay = False,
volume = 1,
balance = 0,
on_duration_changed = lambda e: log_init.logging.info("Duration changed:" + e.data),
on_state_changed = lambda e: log_init.logging.info("State changed:" + e.data),
on_seek_complete = lambda _: log_init.logging.info("Seek complete")
on_state_changed = stateSet,
on_seek_complete = lambda _: log_init.logging.info("Seek complete"),
)
7 changes: 6 additions & 1 deletion pages/settingsPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@
)

playImmediatelyAfterLoaded_switch = ft.Switch(label = i18n.lang.sets["immediatelyPlay"])
defaultPlayInLoop_switch = ft.Switch(label = i18n.lang.sets["defaultLoop"])
defaultVolume_slider = ft.Slider(min = 0, max = 100, divisions = 100, label = "{value}", value = 100)

playSetCard = ft.Card(
content = ft.Container(
content = ft.Column(controls = [
ft.Row(controls = [ft.Icon(ft.icons.PLAY_ARROW_OUTLINED), ft.Text(value = i18n.lang.sets["play"], size = 18)]),
playImmediatelyAfterLoaded_switch
playImmediatelyAfterLoaded_switch,
defaultPlayInLoop_switch,
ft.Text(value = i18n.lang.sets["defaultVolume"]),
defaultVolume_slider
]
),
padding = 15
Expand Down
10 changes: 8 additions & 2 deletions player.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,16 @@ def lyricShow(e):
lyrics_after.visible = True
lyrics_btn.icon = ft.icons.LYRICS
page.update()

def ctrlRowUpdate():
playPause_btn.icon = work.playPause_btn_icon
page.title = work.page_title

# 歌曲播放/暂停
def playOrPauseMusic(e):
if audioFile != None:
work.playOrPauseMusic(audioFile)
playPause_btn.icon = work.playPause_btn_icon
page.title = work.page_title
ctrlRowUpdate()
page.update()

def autoStopKeepAudioProgress(e):
Expand All @@ -308,6 +311,9 @@ def autoKeepAudioProgress(e):
lyricExistAndRead()
elif getReturn == True:
lyricsProcess()
if work.audioState == "completed":
work.resetPlay()
ctrlRowUpdate()
page.update()

def progressCtrl(e):
Expand Down

0 comments on commit b8966e3

Please sign in to comment.