fix audio player js ref error

This commit is contained in:
Nuwan 2024-12-27 23:29:50 +05:30
parent 04a7445f68
commit 315f532719
1 changed files with 10 additions and 10 deletions

View File

@ -60,7 +60,7 @@ const JKAudioPlayer = ({ audioUrl }) => {
}
const togglePlayPause = (e) => {
if (!audio) return;
if (!audio || e === "undefined") return;
if (audio.paused) {
audio.play();
setIsPlaying(true);
@ -70,14 +70,8 @@ const JKAudioPlayer = ({ audioUrl }) => {
}
}
const onVolumeButtonClick = () => {
if (!audio) return;
audio.muted = !audio.muted;
setIsMuted(audio.muted);
}
const onClickTimeline = (e) => {
if (!audio) return;
if (!audio || e === "undefined") return;
let timeToSeek = 0;
try {
let timelineWidth = window.getComputedStyle(audioPlayer.current.querySelector(".timeline")).width;
@ -94,7 +88,7 @@ const JKAudioPlayer = ({ audioUrl }) => {
}
const onVolumeSliderClick = (e) => {
if (!audio) return;
if (!audio || e === "undefined") return;
let volume = .75;
try {
let sliderWidth = window.getComputedStyle(audioPlayer.current.querySelector(".controls .volume-slider")).width;
@ -110,7 +104,13 @@ const JKAudioPlayer = ({ audioUrl }) => {
audioPlayer.current.querySelector(".controls .volume-percentage").style.width = volume * 100 + '%';
}
function getTimeCodeFromNum(num) {
const onVolumeButtonClick = () => {
if (!audio) return;
audio.muted = !audio.muted;
setIsMuted(audio.muted);
}
const getTimeCodeFromNum = (num) => {
let seconds = parseInt(num);
let minutes = parseInt(seconds / 60);
seconds -= minutes * 60;