import { jsx } from "react/jsx-runtime";
import { SugaredField } from "@contember/react-binding";
const getAudioFileDataExtractor = ({
  durationField
}) => ({
  staticRender: () => !!durationField && /* @__PURE__ */ jsx(SugaredField, { field: durationField }),
  extractFileData: ({ objectUrl }) => {
    if (!durationField) {
      return null;
    }
    return new Promise((resolve, reject) => {
      const audio = document.createElement("audio");
      audio.addEventListener("canplay", () => {
        resolve(audio);
      });
      audio.addEventListener("error", () => {
        reject();
      });
      audio.src = objectUrl;
    });
  },
  populateFields: ({ entity, extractedData }) => {
    !!durationField && entity.getField(durationField).updateValue(extractedData.duration);
  }
});
export {
  getAudioFileDataExtractor
};
//# sourceMappingURL=getAudioFileDataExtractor.js.map
