react-use-audio-player
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -33,2 +33,3 @@ import { Howl } from "howler"; | ||
isReady: boolean; | ||
isLoading: boolean; | ||
paused: boolean; | ||
@@ -35,0 +36,0 @@ stopped: boolean; |
@@ -53,2 +53,3 @@ 'use strict'; | ||
isReady: false, | ||
isLoading: false, | ||
looping: false, | ||
@@ -69,2 +70,3 @@ duration: 0, | ||
isReady: howl.state() === "loaded", | ||
isLoading: howl.state() === "loading", | ||
// @ts-ignore _src exists | ||
@@ -86,3 +88,5 @@ src: howl._src, | ||
case ActionTypes.START_LOAD: | ||
return state; | ||
return _extends({}, initStateFromHowl(), { | ||
isLoading: true | ||
}); | ||
case ActionTypes.ON_LOAD: | ||
@@ -352,4 +356,12 @@ // in React 18 there is a weird race condition where ON_LOAD receives a Howl object that has been unloaded | ||
var useAudioPlayer = function useAudioPlayer() { | ||
var howlManager = react.useRef(new HowlInstanceManager()); | ||
var _useHowlEventSync = useHowlEventSync(howlManager.current, react.useReducer(reducer, howlManager.current.getHowl(), initStateFromHowl)), | ||
var howlManager = react.useRef(null); | ||
function getHowlManager() { | ||
if (howlManager.current !== null) { | ||
return howlManager.current; | ||
} | ||
var manager = new HowlInstanceManager(); | ||
howlManager.current = manager; | ||
return manager; | ||
} | ||
var _useHowlEventSync = useHowlEventSync(getHowlManager(), react.useReducer(reducer, getHowlManager().getHowl(), initStateFromHowl)), | ||
state = _useHowlEventSync[0], | ||
@@ -360,3 +372,3 @@ dispatch = _useHowlEventSync[1]; | ||
return function () { | ||
howlManager.current.destroyHowl(); | ||
getHowlManager().destroyHowl(); | ||
}; | ||
@@ -371,3 +383,3 @@ }, []); | ||
options = _ref$ === void 0 ? {} : _ref$; | ||
var howl = howlManager.current.createHowl(_extends({ | ||
var howl = getHowlManager().createHowl(_extends({ | ||
src: src | ||
@@ -381,3 +393,3 @@ }, options)); | ||
var seek = react.useCallback(function (seconds) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -390,3 +402,3 @@ return; | ||
var _howl$seek; | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -398,3 +410,3 @@ return 0; | ||
var play = react.useCallback(function () { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -406,3 +418,3 @@ return; | ||
var pause = react.useCallback(function () { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -414,3 +426,3 @@ return; | ||
var togglePlayPause = react.useCallback(function () { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -426,3 +438,3 @@ return; | ||
var stop = react.useCallback(function () { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -434,3 +446,3 @@ return; | ||
var fade = react.useCallback(function (from, to, duration) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -442,3 +454,3 @@ return; | ||
var setRate = react.useCallback(function (speed) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -450,3 +462,3 @@ return; | ||
var setVolume = react.useCallback(function (vol) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -458,3 +470,3 @@ return; | ||
var mute = react.useCallback(function (muteOnOff) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -466,3 +478,3 @@ return; | ||
var loop = react.useCallback(function (loopOnOff) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -469,0 +481,0 @@ return; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("howler");function o(){return(o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e}).apply(this,arguments)}function n(e){if(void 0===e)return{src:null,isReady:!1,looping:!1,duration:0,rate:1,volume:1,muted:!1,playing:!1,paused:!1,stopped:!1,error:null};var t=e.seek(),o=e.playing();return{isReady:"loaded"===e.state(),src:e._src,looping:e.loop(),duration:e.duration(),rate:e.rate(),volume:e.volume(),muted:e.mute(),playing:o,paused:!o,stopped:!o&&0===t,error:null}}function l(e,t){switch(t.type){case"START_LOAD":return e;case"ON_LOAD":return"unloaded"===t.howl.state()?e:n(t.howl);case"ON_ERROR":return o({},n(),{error:t.message});case"ON_PLAY":return o({},e,{playing:!0,paused:!1,stopped:!1});case"ON_PAUSE":return o({},e,{playing:!1,paused:!0});case"ON_STOP":return o({},e,{playing:!1,paused:!1,stopped:!0});case"ON_END":return o({},e,{playing:e.looping,stopped:!e.looping});case"ON_MUTE":var l;return o({},e,{muted:null!==(l=t.howl.mute())&&void 0!==l&&l});case"ON_RATE":var r,u;return o({},e,{rate:null!==(r=null===(u=t.howl)||void 0===u?void 0:u.rate())&&void 0!==r?r:1});case"ON_VOLUME":var a,i;return o({},e,{volume:null!==(a=null===(i=t.howl)||void 0===i?void 0:i.volume())&&void 0!==a?a:1});case"ON_LOOP":var s=t.toggleValue,c=void 0!==s&&s;return t.howl.loop(c),o({},e,{looping:c});default:return e}}function r(t,o){var n=o[0],l=o[1],r=e.useCallback((function(){var e=t.getHowl();l({type:"ON_LOAD",howl:e})}),[l,t]),u=e.useCallback((function(e,t){l({type:"ON_ERROR",message:t})}),[l]),a=e.useCallback((function(){var e=t.getHowl();l({type:"ON_PLAY",howl:e})}),[l,t]),i=e.useCallback((function(){var e=t.getHowl();l({type:"ON_PAUSE",howl:e})}),[l,t]),s=e.useCallback((function(){var e=t.getHowl();l({type:"ON_END",howl:e})}),[l,t]),c=e.useCallback((function(){var e=t.getHowl();l({type:"ON_STOP",howl:e})}),[l,t]),f=e.useCallback((function(){var e=t.getHowl();l({type:"ON_MUTE",howl:e})}),[l,t]),v=e.useCallback((function(){var e=t.getHowl();l({type:"ON_VOLUME",howl:e})}),[l,t]),p=e.useCallback((function(){var e=t.getHowl();l({type:"ON_RATE",howl:e})}),[l,t]);return e.useEffect((function(){return function(){var e=t.getHowl();null==e||e.off("loaderror",u),null==e||e.off("playerror",u),null==e||e.off("play",a),null==e||e.off("pause",i),null==e||e.off("end",s),null==e||e.off("stop",c),null==e||e.off("mute",f),null==e||e.off("volume",v),null==e||e.off("rate",p)}}),[]),[n,e.useRef((function(e){if("START_LOAD"===e.type){var t=e.howl;t.once("load",r),t.on("loaderror",u),t.on("playerror",u),t.on("play",a),t.on("pause",i),t.on("end",s),t.on("stop",c),t.on("mute",f),t.on("volume",v),t.on("rate",p)}l(e)})).current]}var u=["initialVolume","initialRate","initialMute"],a=function(){function e(){this.callbacks=new Map,this.howl=void 0,this.options={},this.subscriptionIndex=0}var n=e.prototype;return n.subscribe=function(e){var t=(this.subscriptionIndex++).toString();return this.callbacks.set(t,e),t},n.unsubscribe=function(e){this.callbacks.delete(e)},n.getHowl=function(){return this.howl},n.getNumberOfConnections=function(){return this.callbacks.size},n.createHowl=function(e){this.destroyHowl(),this.options=e;var n=this.options,l=n.initialVolume,r=n.initialRate,a=n.initialMute,i=function(e,t){if(null==e)return{};var o,n,l={},r=Object.keys(e);for(n=0;n<r.length;n++)t.indexOf(o=r[n])>=0||(l[o]=e[o]);return l}(n,u),s=new t.Howl(o({mute:a,volume:l,rate:r},i));return this.callbacks.forEach((function(e){return e({type:"START_LOAD",howl:s})})),this.howl=s,s},n.destroyHowl=function(){var e,t,o,n,l,r;this.options.onload&&(null===(t=this.howl)||void 0===t||t.off("load",this.options.onload)),this.options.onend&&(null===(o=this.howl)||void 0===o||o.off("end",this.options.onend)),this.options.onplay&&(null===(n=this.howl)||void 0===n||n.off("play",this.options.onplay)),this.options.onpause&&(null===(l=this.howl)||void 0===l||l.off("pause",this.options.onpause)),this.options.onstop&&(null===(r=this.howl)||void 0===r||r.off("stop",this.options.onstop)),null===(e=this.howl)||void 0===e||e.unload()},n.broadcast=function(e){this.callbacks.forEach((function(t){return t(e)}))},e}(),i=function(){function e(){}return e.getInstance=function(){return void 0===this.instance&&(e.instance=new a),e.instance},e}();i.instance=void 0,exports.useAudioPlayer=function(){var t=e.useRef(new a),u=r(t.current,e.useReducer(l,t.current.getHowl(),n)),i=u[0],s=u[1];e.useEffect((function(){return function(){t.current.destroyHowl()}}),[]);var c=e.useCallback((function(){for(var e=arguments.length,n=new Array(e),l=0;l<e;l++)n[l]=arguments[l];var r=n[0],u=n[1],a=void 0===u?{}:u,i=t.current.createHowl(o({src:r},a));s({type:"START_LOAD",howl:i})}),[]),f=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.seek(e)}),[]),v=e.useCallback((function(){var e,o=t.current.getHowl();return void 0===o?0:null!==(e=o.seek())&&void 0!==e?e:0}),[]),p=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.play()}),[]),d=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.pause()}),[]),w=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&(i.playing?e.pause():e.play())}),[i]),g=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.stop()}),[]),h=e.useCallback((function(e,o,n){var l=t.current.getHowl();void 0!==l&&l.fade(e,o,n)}),[]),b=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.rate(e)}),[]),y=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.volume(e)}),[]),O=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.mute(e)}),[]),k=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&s({type:"ON_LOOP",howl:o,toggleValue:e})}),[]);return o({},i,{load:c,seek:f,getPosition:v,play:p,pause:d,togglePlayPause:w,stop:g,mute:O,fade:h,setRate:b,setVolume:y,loop:k})},exports.useGlobalAudioPlayer=function(){var t=e.useRef(i.getInstance()),u=r(t.current,e.useReducer(l,t.current.getHowl(),n)),a=u[0],s=u[1];e.useEffect((function(){var e=t.current.getHowl();void 0!==e&&(s({type:"START_LOAD",howl:e}),"loaded"===e.state()&&s({type:"ON_LOAD",howl:e}));var o=t.current.subscribe((function(e){s(e)}));return function(){t.current.unsubscribe(o)}}),[]);var c=e.useCallback((function(){for(var e=arguments.length,n=new Array(e),l=0;l<e;l++)n[l]=arguments[l];var r=n[0],u=n[1],a=void 0===u?{}:u;t.current.createHowl(o({src:r},a))}),[]),f=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.seek(e)}),[]),v=e.useCallback((function(){var e,o=t.current.getHowl();return void 0===o?0:null!==(e=o.seek())&&void 0!==e?e:0}),[]),p=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.play()}),[]),d=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.pause()}),[]),w=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&(a.playing?e.pause():e.play())}),[a]),g=e.useCallback((function(){var e=t.current.getHowl();void 0!==e&&e.stop()}),[]),h=e.useCallback((function(e,o,n){var l=t.current.getHowl();void 0!==l&&l.fade(e,o,n)}),[]),b=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.rate(e)}),[]),y=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.volume(e)}),[]),O=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&o.mute(e)}),[]),k=e.useCallback((function(e){var o=t.current.getHowl();void 0!==o&&t.current.broadcast({type:"ON_LOOP",howl:o,toggleValue:e})}),[]);return o({},a,{load:c,seek:f,getPosition:v,play:p,pause:d,togglePlayPause:w,stop:g,mute:O,fade:h,setRate:b,setVolume:y,loop:k})}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),o=require("howler");function t(){return(t=Object.assign?Object.assign.bind():function(e){for(var o=1;o<arguments.length;o++){var t=arguments[o];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function n(e){if(void 0===e)return{src:null,isReady:!1,isLoading:!1,looping:!1,duration:0,rate:1,volume:1,muted:!1,playing:!1,paused:!1,stopped:!1,error:null};var o=e.seek(),t=e.playing();return{isReady:"loaded"===e.state(),isLoading:"loading"===e.state(),src:e._src,looping:e.loop(),duration:e.duration(),rate:e.rate(),volume:e.volume(),muted:e.mute(),playing:t,paused:!t,stopped:!t&&0===o,error:null}}function l(e,o){switch(o.type){case"START_LOAD":return t({},n(),{isLoading:!0});case"ON_LOAD":return"unloaded"===o.howl.state()?e:n(o.howl);case"ON_ERROR":return t({},n(),{error:o.message});case"ON_PLAY":return t({},e,{playing:!0,paused:!1,stopped:!1});case"ON_PAUSE":return t({},e,{playing:!1,paused:!0});case"ON_STOP":return t({},e,{playing:!1,paused:!1,stopped:!0});case"ON_END":return t({},e,{playing:e.looping,stopped:!e.looping});case"ON_MUTE":var l;return t({},e,{muted:null!==(l=o.howl.mute())&&void 0!==l&&l});case"ON_RATE":var a,u;return t({},e,{rate:null!==(a=null===(u=o.howl)||void 0===u?void 0:u.rate())&&void 0!==a?a:1});case"ON_VOLUME":var r,i;return t({},e,{volume:null!==(r=null===(i=o.howl)||void 0===i?void 0:i.volume())&&void 0!==r?r:1});case"ON_LOOP":var s=o.toggleValue,c=void 0!==s&&s;return o.howl.loop(c),t({},e,{looping:c});default:return e}}function a(o,t){var n=t[0],l=t[1],a=e.useCallback((function(){var e=o.getHowl();l({type:"ON_LOAD",howl:e})}),[l,o]),u=e.useCallback((function(e,o){l({type:"ON_ERROR",message:o})}),[l]),r=e.useCallback((function(){var e=o.getHowl();l({type:"ON_PLAY",howl:e})}),[l,o]),i=e.useCallback((function(){var e=o.getHowl();l({type:"ON_PAUSE",howl:e})}),[l,o]),s=e.useCallback((function(){var e=o.getHowl();l({type:"ON_END",howl:e})}),[l,o]),c=e.useCallback((function(){var e=o.getHowl();l({type:"ON_STOP",howl:e})}),[l,o]),f=e.useCallback((function(){var e=o.getHowl();l({type:"ON_MUTE",howl:e})}),[l,o]),v=e.useCallback((function(){var e=o.getHowl();l({type:"ON_VOLUME",howl:e})}),[l,o]),p=e.useCallback((function(){var e=o.getHowl();l({type:"ON_RATE",howl:e})}),[l,o]);return e.useEffect((function(){return function(){var e=o.getHowl();null==e||e.off("loaderror",u),null==e||e.off("playerror",u),null==e||e.off("play",r),null==e||e.off("pause",i),null==e||e.off("end",s),null==e||e.off("stop",c),null==e||e.off("mute",f),null==e||e.off("volume",v),null==e||e.off("rate",p)}}),[]),[n,e.useRef((function(e){if("START_LOAD"===e.type){var o=e.howl;o.once("load",a),o.on("loaderror",u),o.on("playerror",u),o.on("play",r),o.on("pause",i),o.on("end",s),o.on("stop",c),o.on("mute",f),o.on("volume",v),o.on("rate",p)}l(e)})).current]}var u=["initialVolume","initialRate","initialMute"],r=function(){function e(){this.callbacks=new Map,this.howl=void 0,this.options={},this.subscriptionIndex=0}var n=e.prototype;return n.subscribe=function(e){var o=(this.subscriptionIndex++).toString();return this.callbacks.set(o,e),o},n.unsubscribe=function(e){this.callbacks.delete(e)},n.getHowl=function(){return this.howl},n.getNumberOfConnections=function(){return this.callbacks.size},n.createHowl=function(e){this.destroyHowl(),this.options=e;var n=this.options,l=n.initialVolume,a=n.initialRate,r=n.initialMute,i=function(e,o){if(null==e)return{};var t,n,l={},a=Object.keys(e);for(n=0;n<a.length;n++)o.indexOf(t=a[n])>=0||(l[t]=e[t]);return l}(n,u),s=new o.Howl(t({mute:r,volume:l,rate:a},i));return this.callbacks.forEach((function(e){return e({type:"START_LOAD",howl:s})})),this.howl=s,s},n.destroyHowl=function(){var e,o,t,n,l,a;this.options.onload&&(null===(o=this.howl)||void 0===o||o.off("load",this.options.onload)),this.options.onend&&(null===(t=this.howl)||void 0===t||t.off("end",this.options.onend)),this.options.onplay&&(null===(n=this.howl)||void 0===n||n.off("play",this.options.onplay)),this.options.onpause&&(null===(l=this.howl)||void 0===l||l.off("pause",this.options.onpause)),this.options.onstop&&(null===(a=this.howl)||void 0===a||a.off("stop",this.options.onstop)),null===(e=this.howl)||void 0===e||e.unload()},n.broadcast=function(e){this.callbacks.forEach((function(o){return o(e)}))},e}(),i=function(){function e(){}return e.getInstance=function(){return void 0===this.instance&&(e.instance=new r),e.instance},e}();i.instance=void 0,exports.useAudioPlayer=function(){var o=e.useRef(null);function u(){if(null!==o.current)return o.current;var e=new r;return o.current=e,e}var i=a(u(),e.useReducer(l,u().getHowl(),n)),s=i[0],c=i[1];e.useEffect((function(){return function(){u().destroyHowl()}}),[]);var f=e.useCallback((function(){for(var e=arguments.length,o=new Array(e),n=0;n<e;n++)o[n]=arguments[n];var l=o[0],a=o[1],r=void 0===a?{}:a,i=u().createHowl(t({src:l},r));c({type:"START_LOAD",howl:i})}),[]),v=e.useCallback((function(e){var o=u().getHowl();void 0!==o&&o.seek(e)}),[]),p=e.useCallback((function(){var e,o=u().getHowl();return void 0===o?0:null!==(e=o.seek())&&void 0!==e?e:0}),[]),d=e.useCallback((function(){var e=u().getHowl();void 0!==e&&e.play()}),[]),w=e.useCallback((function(){var e=u().getHowl();void 0!==e&&e.pause()}),[]),g=e.useCallback((function(){var e=u().getHowl();void 0!==e&&(s.playing?e.pause():e.play())}),[s]),h=e.useCallback((function(){var e=u().getHowl();void 0!==e&&e.stop()}),[]),b=e.useCallback((function(e,o,t){var n=u().getHowl();void 0!==n&&n.fade(e,o,t)}),[]),y=e.useCallback((function(e){var o=u().getHowl();void 0!==o&&o.rate(e)}),[]),O=e.useCallback((function(e){var o=u().getHowl();void 0!==o&&o.volume(e)}),[]),k=e.useCallback((function(e){var o=u().getHowl();void 0!==o&&o.mute(e)}),[]),H=e.useCallback((function(e){var o=u().getHowl();void 0!==o&&c({type:"ON_LOOP",howl:o,toggleValue:e})}),[]);return t({},s,{load:f,seek:v,getPosition:p,play:d,pause:w,togglePlayPause:g,stop:h,mute:k,fade:b,setRate:y,setVolume:O,loop:H})},exports.useGlobalAudioPlayer=function(){var o=e.useRef(i.getInstance()),u=a(o.current,e.useReducer(l,o.current.getHowl(),n)),r=u[0],s=u[1];e.useEffect((function(){var e=o.current.getHowl();void 0!==e&&(s({type:"START_LOAD",howl:e}),"loaded"===e.state()&&s({type:"ON_LOAD",howl:e}));var t=o.current.subscribe((function(e){s(e)}));return function(){o.current.unsubscribe(t)}}),[]);var c=e.useCallback((function(){for(var e=arguments.length,n=new Array(e),l=0;l<e;l++)n[l]=arguments[l];var a=n[0],u=n[1],r=void 0===u?{}:u;o.current.createHowl(t({src:a},r))}),[]),f=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.seek(e)}),[]),v=e.useCallback((function(){var e,t=o.current.getHowl();return void 0===t?0:null!==(e=t.seek())&&void 0!==e?e:0}),[]),p=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&e.play()}),[]),d=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&e.pause()}),[]),w=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&(r.playing?e.pause():e.play())}),[r]),g=e.useCallback((function(){var e=o.current.getHowl();void 0!==e&&e.stop()}),[]),h=e.useCallback((function(e,t,n){var l=o.current.getHowl();void 0!==l&&l.fade(e,t,n)}),[]),b=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.rate(e)}),[]),y=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.volume(e)}),[]),O=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&t.mute(e)}),[]),k=e.useCallback((function(e){var t=o.current.getHowl();void 0!==t&&o.current.broadcast({type:"ON_LOOP",howl:t,toggleValue:e})}),[]);return t({},r,{load:c,seek:f,getPosition:v,play:p,pause:d,togglePlayPause:w,stop:g,mute:O,fade:h,setRate:b,setVolume:y,loop:k})}; | ||
//# sourceMappingURL=react-use-audio-player.cjs.production.min.js.map |
@@ -49,2 +49,3 @@ import { useCallback, useEffect, useRef, useReducer } from 'react'; | ||
isReady: false, | ||
isLoading: false, | ||
looping: false, | ||
@@ -65,2 +66,3 @@ duration: 0, | ||
isReady: howl.state() === "loaded", | ||
isLoading: howl.state() === "loading", | ||
// @ts-ignore _src exists | ||
@@ -82,3 +84,5 @@ src: howl._src, | ||
case ActionTypes.START_LOAD: | ||
return state; | ||
return _extends({}, initStateFromHowl(), { | ||
isLoading: true | ||
}); | ||
case ActionTypes.ON_LOAD: | ||
@@ -348,4 +352,12 @@ // in React 18 there is a weird race condition where ON_LOAD receives a Howl object that has been unloaded | ||
var useAudioPlayer = function useAudioPlayer() { | ||
var howlManager = useRef(new HowlInstanceManager()); | ||
var _useHowlEventSync = useHowlEventSync(howlManager.current, useReducer(reducer, howlManager.current.getHowl(), initStateFromHowl)), | ||
var howlManager = useRef(null); | ||
function getHowlManager() { | ||
if (howlManager.current !== null) { | ||
return howlManager.current; | ||
} | ||
var manager = new HowlInstanceManager(); | ||
howlManager.current = manager; | ||
return manager; | ||
} | ||
var _useHowlEventSync = useHowlEventSync(getHowlManager(), useReducer(reducer, getHowlManager().getHowl(), initStateFromHowl)), | ||
state = _useHowlEventSync[0], | ||
@@ -356,3 +368,3 @@ dispatch = _useHowlEventSync[1]; | ||
return function () { | ||
howlManager.current.destroyHowl(); | ||
getHowlManager().destroyHowl(); | ||
}; | ||
@@ -367,3 +379,3 @@ }, []); | ||
options = _ref$ === void 0 ? {} : _ref$; | ||
var howl = howlManager.current.createHowl(_extends({ | ||
var howl = getHowlManager().createHowl(_extends({ | ||
src: src | ||
@@ -377,3 +389,3 @@ }, options)); | ||
var seek = useCallback(function (seconds) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -386,3 +398,3 @@ return; | ||
var _howl$seek; | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -394,3 +406,3 @@ return 0; | ||
var play = useCallback(function () { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -402,3 +414,3 @@ return; | ||
var pause = useCallback(function () { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -410,3 +422,3 @@ return; | ||
var togglePlayPause = useCallback(function () { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -422,3 +434,3 @@ return; | ||
var stop = useCallback(function () { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -430,3 +442,3 @@ return; | ||
var fade = useCallback(function (from, to, duration) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -438,3 +450,3 @@ return; | ||
var setRate = useCallback(function (speed) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -446,3 +458,3 @@ return; | ||
var setVolume = useCallback(function (vol) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -454,3 +466,3 @@ return; | ||
var mute = useCallback(function (muteOnOff) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -462,3 +474,3 @@ return; | ||
var loop = useCallback(function (loopOnOff) { | ||
var howl = howlManager.current.getHowl(); | ||
var howl = getHowlManager().getHowl(); | ||
if (howl === undefined) { | ||
@@ -465,0 +477,0 @@ return; |
{ | ||
"name": "react-use-audio-player", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "React hook for building custom audio playback controls", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
167208
1391