'use strict'
!(function(require, directRequire) {
  function a(a, b) {
    let c,
      d = 0 === b.indexOf('http') && !j.isLocalId(b)
    if (d) return void (a.src = b)
    let g = i.getCurrent(),
      h = j.getFileRealPath(b, g),
      k = h.fileRealPath
    if (-1 !== b.indexOf('durationTime=')) {
      let d = f.extname(b),
        g = b.replace(/.*durationTime=/, '').replace(d, '')
      g && (a._duration = g / 1e3),
        (c = e.readFileSync(h.fileRealPath, 'utf8')),
        c.startsWith('data:audio/') ||
          ((c = e.readFileSync(h.fileRealPath, { encoding: 'base64' })),
          (c = `data:audio/mpeg;base64,${c}`)),
        (a.src = c)
    } else
      (c = e.readFileSync(h.fileRealPath)),
        (a.src = `data:audio/mpeg;base64,${c.toString('base64')}`)
  }
  function b(a) {
    let b = h()
    b.triggerOnEvent({ eventName: 'onAudioStateChange', data: a })
  }
  function c(a) {
    let c = a ? a.buffered : ''
    if (c) {
      let d = a.currentTime
      for (let a, b = 0, e = c.length; b < e; b++)
        if (((a = c), c.start(b) <= d && c.end(b) >= d)) return c.end(b)
    }
    return 0
  }
  function d(a) {
    let c = m[a]
    c.initStateChage ||
      ((c.initStateChage = !0),
      c.addEventListener('error', c => {
        let d = c.currentTarget.error.code,
          e = {
            audioId: a,
            state: 'error',
            errMsg: 'MediaError',
            errCode: 1e4 + parseInt(d)
          }
        b(e)
      }),
      c.addEventListener('pause', () => {
        let d = c._isStop ? 'stop' : 'pause'
        c._isStop = !1
        b({ audioId: a, state: d })
      }),
      l.forEach(d => {
        c.addEventListener(d, () => {
          b({ audioId: a, state: d })
        })
      }))
  }
  const e = require('fs'),
    f = require('path'),
    g = require('./0634ee2ebd3e560d9d4804ecc960160f.js'),
    h = require('./dfd9a72b9ff6078018aa4a64eed949a5.js'),
    i = require('./3bfffbe88b3d923921f851c0697974fe.js'),
    j = require('./f6cbcecf6ed9f533f6a506310d8f07b6.js'),
    k = require('./37be435102276ea9cf47609ff6535cd4.js'),
    l = ['play', 'canplay', 'ended', 'stop', 'waiting', 'seeking', 'seeked']
  var m = {}
  module.exports = {
    createAudioInstance: async function(a, b) {
      let c = `${Date.now()}${Math.random()}`,
        d = document.createElement('audio')
      return (m[c] = d), { errMsg: `${b.api}:ok`, audioId: c }
    },
    destroyAudioInstance: function(a, b) {
      let c = b.args,
        d = c.audioId
      return (
        m[d] && (m[d].pause(), m[d].remove(), delete m[d]),
        { errMsg: `${b.api}:ok`, audioId: d }
      )
    },
    setAudioState: async function(b, c) {
      let e = c.args,
        {
          audioId: f,
          src: g,
          startTime: h,
          autoplay: i,
          loop: j,
          obeyMuteSwitch: k,
          volume: l
        } = e,
        n = m[f]
      if (
        ((n.loop = j || !1),
        (n.autoplay = i || !1),
        (l = parseFloat(l)),
        (n.volume = isNaN(l)
          ? 1
          : void 0 === Math.max(0, Math.min(1, l))
            ? 1
            : l),
        g && a(n, g),
        h)
      ) {
        const a = () => {
          n.removeEventListener('canplay', a), (n.currentTime = h / 1e3)
        }
        n.addEventListener('canplay', a)
      }
      return (n.startTime = h || 0), d(f), { errMsg: `${c.api}:ok` }
    },
    getAudioState: async function(a, b) {
      let d = b.args,
        e = d.audioId,
        f = m[e],
        {
          duration: g,
          currentTime: h,
          paused: i,
          src: j,
          startTime: k,
          volume: l
        } = f,
        n = c(f)
      return (
        g === Infinity && f._duration && (g = f._duration),
        {
          errMsg: `${b.api}:ok`,
          duration: 1e3 * g,
          currentTime: 1e3 * h,
          paused: i,
          src: j,
          startTime: 1e3 * k,
          buffered: 1e3 * n
        }
      )
    },
    operateAudio: async function(a, b) {
      let c = b.args,
        { operationType: d, audioId: e, currentTime: f } = c,
        g = m[e]
      return (
        'play' === d
          ? g.play()
          : 'pause' === d
            ? g.pause()
            : 'stop' === d
              ? ((g._isStop = !0), g.pause(), (g.currentTime = 0))
              : 'seek' === d && (g.currentTime = f / 1e3),
        { errMsg: `${b.api}:ok` }
      )
    },
    removeAudio: function() {
      for (let a in m) m[a].pause(), m[a].remove()
      m = {}
    }
  }
})(require('lazyload'), require)
