class ListPlayer extends EventEmitter { // eslint-disable-line
  constructor (options = {}) {
    super()
    this.tracks = (options.tracks || []).map((t) => {
      if (typeof t === 'string') return { src: t }
      return t
    })
    this.loopTracks = options.loopTracks || true
    this.el = this._injectAudioElement()
    this.index = 0
    this._loadTrack()
    if (this.advanced) this._loadAudioContext()
  }

  play () {
    this.emit('play')
    this._loadTrack()
    return this.el.play()
  }

  pause () {
    this.emit('pause')
    return this.el.pause()
  }

  next () {
    this.emit('next')
    this.index++
    if (this.index > this.tracks.length) {
      if (this.loopTracks) {
        this.index = 0
      } else {
        this.index--
        this.emit('error', 'you are on the last track')
      }
    }
    this._loadTrack()
    if (this.playing()) this.play()
  }

  prev () {
    this.emit('prev')
    this.index--
    if (this.index < 0) {
      if (this.loopTracks) {
        this.index = this.tracks.length
      } else {
        this.index++
        this.emit('error', 'you are on the first track')
      }
    }
    this._loadTrack()
    if (this.playing()) this.play()
  }

  playing () {
    return !this.el.paused
  }

  seek (time) {
    if (!time) return this.el.currentTime
    this.emit('seek', time)
    this.el.currentTime = time
  }

  /**
   * Injects an audio element to the body and hides it.
   * @private
   */
  _injectAudioElement () {
    const el = document.createElement('audio')
    document.body.appendChild(el)
    el.style.display = 'none'
    return el
  }

  /**
   * Loads a track into the player
   * @private
   */
  _loadTrack () {
    if (this._loadedTrack === this.index) return
    this.el.innerHTML = ''

    this.currentTrack = this.tracks[this.index]
    const source = document.createElement('source')
    source.src = this.currentTrack.src
    source.type = 'audio/mp3'

    this.el.appendChild(source)
    this.el.load()
    this._loadedTrack = this.index
  }

  _loadAudioContext () {
    const AudioContext = window.AudioContext || window.webkitAudioContext
    if (!AudioContext) return this.emit('error', 'web audio api unsupported')
    this.ctx = new AudioContext()
    this.src = this.ctx.createMediaElementSource(this.el)
  }
}

@@ -636,16 +636,17 @@
 .index %3E
+=
  this.tr
@@ -810,32 +810,71 @@
 )%0A      %7D%0A    %7D%0A
+    const _wasPlaying = this.playing()%0A
     this._loadTr
@@ -883,38 +883,35 @@
 k()%0A    if (
-this.p
+_wasP
 laying
-()
 ) this.play(
@@ -988,16 +988,17 @@
 .index %3C
+=
  0) %7B%0A  
@@ -1167,24 +1167,63 @@
     %7D%0A    %7D%0A
+    const _wasPlaying = this.playing()%0A
     this._lo
@@ -1240,30 +1240,27 @@
     if (
-this.p
+_wasP
 laying
-()
 ) this.p

index loop fix, next/prev while playing fix