File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,11 @@ export function APlayer({
5454
5555 const audioControl = useAudioControl ( {
5656 initialVolume : volume ,
57+ onError ( ) {
58+ if ( playlist . hasNextSong ) {
59+ playlist . next ( )
60+ }
61+ } ,
5762 onEnded ( ) {
5863 if ( playlist . hasNextSong ) {
5964 playlist . next ( )
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ function useCreateAudioElement(
2020 | "onEnded"
2121 | "onWaiting"
2222 | "onCanPlay"
23+ | "onError"
2324 > ,
2425) {
2526 const audioElementRef = useRef < HTMLAudioElement > ( )
@@ -55,6 +56,18 @@ function useCreateAudioElement(
5556 }
5657 } , [ options ?. onWaiting ] )
5758
59+ useEffect ( ( ) => {
60+ const audio = audioElementRef . current
61+
62+ if ( audio && options ?. onError ) {
63+ audio . addEventListener ( "error" , options . onError )
64+
65+ return ( ) => {
66+ audio . removeEventListener ( "error" , options . onError )
67+ }
68+ }
69+ } , [ options ?. onError ] )
70+
5871 useEffect ( ( ) => {
5972 const audio = audioElementRef . current
6073
@@ -100,7 +113,7 @@ type UseAudioControlOptions = CreateAudioElementOptions &
100113 React . AudioHTMLAttributes < HTMLAudioElement > ,
101114 HTMLAudioElement
102115 > ,
103- "onEnded"
116+ "onEnded" | "onError"
104117 >
105118
106119export function useAudioControl ( options : UseAudioControlOptions ) {
@@ -133,6 +146,7 @@ export function useAudioControl(options: UseAudioControlOptions) {
133146 onCanPlay ( ) {
134147 setLoading ( false )
135148 } ,
149+ onError : options . onError ,
136150 onEnded : options . onEnded ,
137151 } )
138152 const [ isLoading , setLoading ] = useState ( false )
You can’t perform that action at this time.
0 commit comments