@@ -64,7 +64,7 @@ def __init__(self, parent=None):
64
64
self ._init_signal ()
65
65
self ._init_media_session ()
66
66
67
- self .calibration_event ()
67
+ self .calibration_event (use_api_position = True )
68
68
69
69
def _re_init (self ):
70
70
"""重新初始化"""
@@ -124,21 +124,26 @@ def media_properties_changed(self, info: MediaPropertiesInfo):
124
124
125
125
track_title = f"{ info .title } - { info .artist } "
126
126
track_id = self .lyric_file_manage .get_id (track_title )
127
-
128
- if not self ._manual_skip_flag :
129
- # 自动切换到下一首歌 将会有将近700ms的歌曲准备时间导致时间定位不准确
130
- time .sleep (0.7 )
131
- self .media_session .seek_to_position_media (0 )
132
- self ._manual_skip_flag = True
133
- else :
134
- # 手动切换到下一首歌 可能会有延迟也可能没有,故不做处理
135
- time .sleep (0.5 ) # 等待api反应过来
136
-
137
127
if track_id and not self .lyric_file_manage .get_not_found (track_id ): # 如果可以通过title直接获取id, 则不走api渠道
138
128
playback_info = self .media_session .get_current_playback_info ()
139
- self .playback_info_changed (playback_info )
140
129
self .lrc_player .set_track (track_id , playback_info .duration )
130
+ if not self ._manual_skip_flag :
131
+ # 自动切换到下一首歌 将会有将近700ms的歌曲准备时间导致时间定位不准确
132
+ time .sleep (0.7 )
133
+ self .media_session .seek_to_position_media (0 )
134
+ self .lrc_player .seek_to_position (0 )
135
+ self ._manual_skip_flag = True
136
+ self .lrc_player .set_pause (not (playback_info .playStatus == 4 ))
141
137
else :
138
+ if not self ._manual_skip_flag :
139
+ # 自动切换到下一首歌 将会有将近700ms的歌曲准备时间导致时间定位不准确
140
+ time .sleep (0.7 )
141
+ self .media_session .seek_to_position_media (0 )
142
+ self .lrc_player .seek_to_position (0 )
143
+ self ._manual_skip_flag = True
144
+ else :
145
+ # 手动切换到下一首歌 可能会有延迟也可能没有,故不做处理
146
+ time .sleep (0.5 ) # 等待api反应过来
142
147
self .calibration_event ()
143
148
144
149
def playback_info_changed (self , info : MediaPlaybackInfo ):
@@ -149,18 +154,22 @@ def playback_info_changed(self, info: MediaPlaybackInfo):
149
154
self .set_lyrics_rolling (is_playing )
150
155
151
156
def timeline_properties_changed (self , info : MediaPlaybackInfo ):
157
+ if not self ._manual_skip_flag :
158
+ return
152
159
if info .position < 500 or self .lrc_player .is_pause :
153
160
# 由于切换到下一首歌会同时触发timeline和properties的变化信号,利用position<500过滤掉切换歌时候的timeline信号
161
+ self .lrc_player .seek_to_position (info .position , is_show_last_lyric = False )
154
162
return
155
163
self .lrc_player .seek_to_position (info .position )
156
164
157
165
@thread_drive ()
158
166
@CatchError
159
- def calibration_event (self , * _ , no_text_show : bool = False ):
167
+ def calibration_event (self , * _ , no_text_show : bool = False , use_api_position : bool = False ):
160
168
"""
161
169
同步歌词
162
170
163
171
:param no_text_show: 是否显示 calibrating! 的 正在校准提示
172
+ :param use_api_position: 是否使用api的时间进行校准
164
173
"""
165
174
if not no_text_show :
166
175
self .set_lyrics_text (1 , "calibrating!" )
@@ -194,12 +203,9 @@ def calibration_event(self, *_, no_text_show: bool = False):
194
203
self .lyric_file_manage .set_not_found (user_current .track_id , "" ) # 将 不存在 记录撤去
195
204
user_current = self ._refresh_player_track (user_current )
196
205
197
- ava_trans = self .lrc_player .lrc_file .available_trans ()
198
-
199
206
self .lrc_player .set_pause (not user_current .is_playing )
200
- self .lrc_player .set_trans_mode (self .user_trans if self .user_trans in ava_trans else TransType .NON )
201
207
202
- if not self .media_session .is_connected ():
208
+ if not self .media_session .is_connected () or use_api_position :
203
209
self .lrc_player .seek_to_position (user_current .progress_ms )
204
210
205
211
@thread_drive ()
0 commit comments