Skip to content

Next track automatically starts despite being paused #15

@probablykasper

Description

@probablykasper

In my code below, I'm adding a few tracks, and then I have player.togglePlayPause() connected to a button's click event. When I call click the button to start playback, then click it again shortly afterwards to pause, the next track will start playing about 3 minutes later (the length of the song).

This issue happens in 2.2.3. I tested 1.0.0 as well, and it's an issue there as well.

// import Gapless from 'gapless.js'
import Gapless from '../../gapless2.js'
let sliderBeingDragged = false
let currentTime = 0
let duration = 0
let sliderValue = 0
const sliderSteps = 400
const player = new Gapless.Queue({
  numberOfTracksToPreload: 2,
  onProgress: (track) => {
    if (track) {
      currentTime = track.currentTime
      duration = track.duration
      if (!sliderBeingDragged && duration > 0) {
        sliderValue = currentTime/duration*sliderSteps
      }
    }
  },
})
const tracks = [
  '/Users/kasper/Downloads/01 Neo-Seoul (Part 1).m4a',
  '/Users/kasper/Downloads/02 Neo-Tokyo (Part 2).m4a',
  '/Users/kasper/Downloads/03 Aeon Metropolis (Part 3).m4a',
  '/Users/kasper/Downloads/04 Goodnight Sequence (part 4).m4a',
]
for (const track of tracks) {
  player.addTrack({ trackUrl: 'file://'+track })
}
function playPause() { // this function is tied to a button onclick
  player.togglePlayPause()
}

Below is the console log from when this happens. Once the next track starts playing by itself, the first log message is for the onEnded event.
Screen Shot 2020-12-26 at 1 03 16 AM

I've noticed that running track.loadBuffer() causes the track to start playing, so perhaps that's related.

Woud love to see what's causing this, and whether there's an easy fix for it. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions