/* eslint-disable */
export default function musicPlay (src) {
  var className = 'play'
  var trigger = 'ontouchend' in document ? 'touchstart' : 'click'
  var $musci = document.createElement('div')
  var $audio = document.createElement('audio')

  function start () {
    document.removeEventListener(trigger, start, false)
    if (!$audio.paused) return
    $audio.play()
  }

  function toggle () {
    if (!$audio.paused) return $audio.pause()

    $audio.currentTime = 0
    $audio.play()
  }

  function play (e) {
    $musci.classList.add(className)
  }

  function pause (e) {
    $musci.classList.remove(className)
  }

  $musci.className = 'music-icon'
  $musci.classList.add('paused')
  $audio.src = src
  $audio.id = "audio"
  $audio.loop = true
  $audio.volume = 0.5
  document.body.appendChild($musci)
  document.body.appendChild($audio)

  $audio.addEventListener('play', play, false)
  $audio.addEventListener('pause', pause, false)
  $audio.addEventListener('ended', pause, false)
  $musci.addEventListener('click', toggle, false)
  try {
    $audio.play()
  } catch (err) {
  }
  document.addEventListener("WeixinJSBridgeReady", function () {
    $audio.play()
  }, false)

  document.addEventListener(trigger, start, false)
}