Skip to content

Commit

Permalink
Merge branch 'develop' into fix/optionInput
Browse files Browse the repository at this point in the history
  • Loading branch information
juliajforesti authored Sep 11, 2023
2 parents 37f6fb6 + 385170c commit 9713ffa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 34 additions & 2 deletions packages/fuselage/src/components/AudioPlayer/AudioPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,32 @@ function forceDownload(url: string, fileName?: string) {
xhr.send();
}

const getDurationForInfinityDurationAudioFile = (
src: string,
callback: (duration: number) => void
) => {
const audioElement = new Audio();
audioElement.src = src;

audioElement.addEventListener('loadedmetadata', () => {
const { duration } = audioElement;
if (duration === Infinity) {
audioElement.currentTime = 1e101;
return;
}

return callback(duration);
});

audioElement.addEventListener('durationchange', () => {
if (audioElement.duration === Infinity) {
return;
}
callback(audioElement.duration);
audioElement.remove();
});
};

export const AudioPlayer = forwardRef<
HTMLAudioElement,
{
Expand Down Expand Up @@ -169,8 +195,14 @@ export const AudioPlayer = forwardRef<
onTimeUpdate={(e) => {
setCurrentTime((e.target as HTMLAudioElement).currentTime);
}}
onLoadedData={(e) => {
setDurationTime((e.target as HTMLAudioElement).duration);
onLoadedMetadata={(e) => {
const { duration } = e.target as HTMLAudioElement;

if (duration !== Infinity) {
return setDurationTime(duration);
}

getDurationForInfinityDurationAudioFile(src, setDurationTime);
}}
onEnded={() => setIsPlaying(false)}
ref={refs}
Expand Down
4 changes: 4 additions & 0 deletions packages/fuselage/src/styles/primitives/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@
color: map.get($colors, disabled-color);
border-color: map.get($colors, disabled-border-color);
background-color: map.get($colors, disabled-background-color);

* {
transform: none !important;
}
}
}

0 comments on commit 9713ffa

Please sign in to comment.