mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
fix: ensure autoplay on bad encoding
This commit is contained in:
parent
59065d24bc
commit
59e01f90e8
1 changed files with 24 additions and 0 deletions
|
|
@ -225,6 +225,28 @@ export const AudioPlayer = forwardRef<AudioPlayerRef, AudioPlayerProps>((props,
|
||||||
setIsTransitioning(false);
|
setIsTransitioning(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleOnError = (playerRef: React.RefObject<ReactPlayer>) => {
|
||||||
|
return ({ target }: ErrorEvent) => {
|
||||||
|
const { current: player } = playerRef;
|
||||||
|
if (!player || !(target instanceof Audio)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { error } = target;
|
||||||
|
if (error?.code !== MediaError.MEDIA_ERR_DECODE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const duration = player.getDuration();
|
||||||
|
const currentTime = player.getCurrentTime();
|
||||||
|
|
||||||
|
// Decode error within last second, handle as track ended
|
||||||
|
if (duration && duration - currentTime < 1) {
|
||||||
|
handleOnEnded();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (status === PlayerStatus.PLAYING) {
|
if (status === PlayerStatus.PLAYING) {
|
||||||
if (currentPlayer === 1) {
|
if (currentPlayer === 1) {
|
||||||
|
|
@ -424,6 +446,7 @@ export const AudioPlayer = forwardRef<AudioPlayerRef, AudioPlayerProps>((props,
|
||||||
muted={muted}
|
muted={muted}
|
||||||
// If there is no stream url, we do not need to handle when the audio finishes
|
// If there is no stream url, we do not need to handle when the audio finishes
|
||||||
onEnded={stream1 ? handleOnEnded : undefined}
|
onEnded={stream1 ? handleOnEnded : undefined}
|
||||||
|
onError={handleOnError(player1Ref)}
|
||||||
onProgress={
|
onProgress={
|
||||||
playbackStyle === PlaybackStyle.GAPLESS ? handleGapless1 : handleCrossfade1
|
playbackStyle === PlaybackStyle.GAPLESS ? handleGapless1 : handleCrossfade1
|
||||||
}
|
}
|
||||||
|
|
@ -443,6 +466,7 @@ export const AudioPlayer = forwardRef<AudioPlayerRef, AudioPlayerProps>((props,
|
||||||
height={0}
|
height={0}
|
||||||
muted={muted}
|
muted={muted}
|
||||||
onEnded={stream2 ? handleOnEnded : undefined}
|
onEnded={stream2 ? handleOnEnded : undefined}
|
||||||
|
onError={handleOnError(player2Ref)}
|
||||||
onProgress={
|
onProgress={
|
||||||
playbackStyle === PlaybackStyle.GAPLESS ? handleGapless2 : handleCrossfade2
|
playbackStyle === PlaybackStyle.GAPLESS ? handleGapless2 : handleCrossfade2
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue