@@ -103,12 +103,10 @@ const MusicPlayer = () => {
103103 if ( isReady . current ) {
104104 if ( isPlaying ) {
105105 const playPromise = audio . play ( )
106- if ( playPromise !== undefined ) {
107- playPromise . catch ( ( error ) => {
108- // 捕获 "The play() request was interrupted" 错误,静默处理
109- console . log ( 'Playback prevented/interrupted (harmless):' , error )
110- } )
111- }
106+ Promise . resolve ( playPromise ) . catch ( ( error ) => {
107+ // 捕获 "The play() request was interrupted" 错误,静默处理
108+ console . log ( 'Playback prevented/interrupted (harmless):' , error )
109+ } )
112110 }
113111 } else {
114112 // 第一次加载组件时不自动播放
@@ -121,9 +119,7 @@ const MusicPlayer = () => {
121119 const audio = audioRef . current
122120 if ( isPlaying ) {
123121 const playPromise = audio . play ( )
124- if ( playPromise !== undefined ) {
125- playPromise . catch ( ( e ) => console . log ( 'Play interaction error:' , e ) )
126- }
122+ Promise . resolve ( playPromise ) . catch ( ( e ) => console . log ( 'Play interaction error:' , e ) )
127123 } else {
128124 audio . pause ( )
129125 }
@@ -250,10 +246,12 @@ const MusicPlayer = () => {
250246 { TRACKS . map ( ( track , index ) => {
251247 const isCurrent = index === currentTrackIndex
252248 return (
253- < div
249+ < button
254250 key = { track . id }
255251 onClick = { ( ) => playTrack ( index ) }
256- className = { `group mb-1 flex cursor-pointer items-center rounded-xl p-3 transition-all duration-200 ${ isCurrent ? 'bg-gray-800/80' : 'text-gray-400 hover:bg-gray-800/40' } ` }
252+ type = "button"
253+ aria-label = { `Play ${ track . title } by ${ track . artist } ` }
254+ className = { `group mb-1 flex w-full items-center rounded-xl p-3 text-left transition-all duration-200 ${ isCurrent ? 'bg-gray-800/80' : 'text-gray-400 hover:bg-gray-800/40' } ` }
257255 >
258256 { /* 序号 / 动态图标 */ }
259257 < div className = "mr-2 flex w-10 items-center justify-center" >
@@ -284,19 +282,11 @@ const MusicPlayer = () => {
284282 { isCurrent && (
285283 < span className = "px-2 text-xs font-medium text-green-500/80" > { isPlaying ? 'Playing' : 'Paused' } </ span >
286284 ) }
287- </ div >
285+ </ button >
288286 )
289287 } ) }
290288 </ div >
291289 </ div >
292-
293- { /* 全局样式 (用于滚动条和旋转) */ }
294- < style > { `
295- .custom-scrollbar::-webkit-scrollbar { width: 4px; }
296- .custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
297- .custom-scrollbar::-webkit-scrollbar-thumb { background: #374151; border-radius: 2px; }
298- .custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #4b5563; }
299- ` } </ style >
300290 </ div >
301291 )
302292}
0 commit comments