@@ -106,7 +106,7 @@ class Player {
106106 }
107107 if ( ! this . player . playing ( ) ) return ;
108108 const currentTime = this . getSeek ( ) ;
109- const duration = Math . floor ( this . player . duration ( ) * 1000 ) ;
109+ const duration = this . getDuration ( ) ;
110110 // 计算进度条距离
111111 const progress = calculateProgress ( currentTime , duration ) ;
112112 // 计算歌词索引(支持 LRC 与逐字 YRC,对唱重叠处理)
@@ -298,7 +298,7 @@ class Player {
298298 }
299299 // 恢复进度(仅在明确指定且大于0时才恢复,避免切换歌曲时意外恢复进度)
300300 if ( seek && seek > 0 ) {
301- const duration = Math . floor ( this . player . duration ( ) * 1000 ) ;
301+ const duration = this . getDuration ( ) ;
302302 // 确保恢复的进度有效且距离歌曲结束大于2秒
303303 if ( duration && seek < duration - 2000 ) {
304304 this . setSeek ( seek ) ;
@@ -914,9 +914,9 @@ class Player {
914914 console . warn ( "⚠️ Player not ready for seek" ) ;
915915 return ;
916916 }
917- if ( time < 0 || time > this . player . duration ( ) ) {
917+ if ( time < 0 || time > this . getDuration ( ) ) {
918918 console . warn ( "⚠️ Invalid seek time" , time ) ;
919- time = Math . max ( 0 , Math . min ( time , this . player . duration ( ) ) ) ;
919+ time = Math . max ( 0 , Math . min ( time , this . getDuration ( ) ) ) ;
920920 }
921921 this . player . seek ( time / 1000 ) ;
922922 statusStore . currentTime = time ;
@@ -930,6 +930,13 @@ class Player {
930930 if ( ! this . player || this . player . state ( ) !== "loaded" ) return 0 ;
931931 return Math . floor ( this . player . seek ( ) * 1000 ) ;
932932 }
933+ /**
934+ * 获取播放时长
935+ * @returns 播放时长(单位:毫秒)
936+ */
937+ getDuration ( ) : number {
938+ return Math . floor ( this . player . duration ( ) * 1000 ) ;
939+ }
933940 /**
934941 * 设置播放速率
935942 * @param rate 播放速率
0 commit comments