import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React from 'react';
var useTrackDuration = function useTrackDuration(audioRef) {
  var _React$useState = React.useState(0),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    trackDuration = _React$useState2[0],
    setTrackDuration = _React$useState2[1];
  React.useEffect(function () {
    var audioNode = audioRef.current;
    if (!audioNode) {
      return;
    }
    var readyState = audioNode.readyState,
      duration = audioNode.duration;
    if (readyState > 0) {
      setTrackDuration(Math.round(duration));
    } else {
      audioNode.onloadedmetadata = function (e) {
        var el = e.target;
        setTrackDuration(Math.round(el.duration));
      };
    }
  }, [audioRef]);
  return trackDuration;
};
export default useTrackDuration;