Browse Source

fix: [AudioPlayer] Compatible with other framework (#2673)

rashagu 9 tháng trước cách đây
mục cha
commit
9a87b78c67

+ 6 - 6
packages/semi-foundation/audioPlayer/foundation.ts

@@ -8,7 +8,7 @@ export interface AudioPlayerAdapter<P = Record<string, any>, S = Record<string,
     handleStatusClick: () => void;
     handleTimeUpdate: () => void;
     handleTrackChange: (direction: 'next' | 'prev') => void;
-    getAudioRef: () => React.RefObject<HTMLAudioElement>;
+    getAudioRef: () => HTMLAudioElement;
     handleTimeChange: (value: number) => void;
     handleSpeedChange: (value: { label: string; value: number }) => void;
     handleSeek: (direction: number) => void;
@@ -23,14 +23,14 @@ class AudioPlayerFoundation extends BaseFoundation<AudioPlayerAdapter> {
     }
 
     initAudioState() {
-        const audioRef = this.getAudioRef();
+        const audioElement = this.getAudioRef();
         const props = this.getProps();
-        
+
         this.setState({
-            totalTime: audioRef.current?.duration || 0,
+            totalTime: audioElement?.duration || 0,
             isPlaying: props.autoPlay,
-            volume: audioRef.current?.volume * 100 || 100,
-            currentRate: { label: '1.0x', value: audioRef.current?.playbackRate || 1 },
+            volume: audioElement?.volume * 100 || 100,
+            currentRate: { label: '1.0x', value: audioElement?.playbackRate || 1 },
         });
     }
 

+ 2 - 2
packages/semi-ui/audioPlayer/index.tsx

@@ -122,7 +122,7 @@ class AudioPlayer extends BaseComponent<AudioPlayerProps, AudioPlayerState> {
                     isPlaying: !this.state.isPlaying,
                 });
             },
-            getAudioRef: () => this.audioRef,
+            getAudioRef: () => this.audioRef.current,
             resetAudioState: () => {
                 this.setState({
                     isPlaying: true,
@@ -380,4 +380,4 @@ class AudioPlayer extends BaseComponent<AudioPlayerProps, AudioPlayerState> {
     }
 }
 
-export default AudioPlayer;
+export default AudioPlayer;