apm-react-audio-player
Advanced tools
Comparing version 1.0.16 to 1.0.17
@@ -97,2 +97,11 @@ 'use strict'; | ||
var isStream = audioRef.current && audioRef.current.currentSrc.includes('stream'); | ||
// Add a new state variable | ||
var _useState11 = React.useState(false), | ||
_useState12 = _slicedToArray(_useState11, 2), | ||
isAudioReady = _useState12[0], | ||
setIsAudioReady = _useState12[1]; | ||
console.log('🟡 audioRef', audioRef); | ||
console.log('🟡 progressBarRef', progressBarRef); | ||
console.log(' audioRef.current ', audioRef.current); | ||
React.useEffect(function () { | ||
@@ -102,8 +111,25 @@ if (currentTime === Number(duration)) { | ||
setIsFinishedPlaying(true); | ||
console.log('🟡 audioRef', audioRef); | ||
console.log('⚪️ progressBarRef', progressBarRef); | ||
if (progressBarRef.current) { | ||
progressBarRef.current.style.setProperty('--seek-before-width', '0%'); | ||
} | ||
} | ||
}, [currentTime]); | ||
var audio = audioRef.current; | ||
// Define a function to set isAudioReady to true when the audio is ready | ||
var handleCanPlayThrough = function handleCanPlayThrough() { | ||
setIsAudioReady(true); | ||
}; | ||
audio.addEventListener('canplaythrough', handleCanPlayThrough); | ||
// Clean up the event listener on unmount | ||
return function () { | ||
audio.removeEventListener('canplaythrough', handleCanPlayThrough); | ||
}; | ||
}, [isPlaying]); | ||
var onLoadedMetadata = function onLoadedMetadata() { | ||
var seconds = Math.floor(audioRef.current.duration); | ||
setDuration(seconds); | ||
if (!isStream) { | ||
if (seconds !== Infinity) { | ||
progressBarRef.current.max = seconds; | ||
@@ -143,6 +169,9 @@ } | ||
var play = function play() { | ||
setIsPlaying(true); | ||
setIsFinishedPlaying(false); | ||
audioRef.current.play(); | ||
if (!isStream) { | ||
if (isAudioReady) { | ||
// if (!isStream) { | ||
// animationRef.current = window.requestAnimationFrame(whilePlaying) | ||
// } | ||
setIsPlaying(true); | ||
setIsFinishedPlaying(false); | ||
audioRef.current.play(); | ||
animationRef.current = window.requestAnimationFrame(whilePlaying); | ||
@@ -304,3 +333,3 @@ } | ||
src: audioSrc, | ||
preload: "none", | ||
preload: "metadata", | ||
onLoadedMetadata: onLoadedMetadata, | ||
@@ -307,0 +336,0 @@ muted: isMuted |
{ | ||
"name": "apm-react-audio-player", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"author": "Jason Phan <jphan@mpr.org>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22910
451