From 2039aa1f2793f414c1c8f6373bbe0e70865f65dd Mon Sep 17 00:00:00 2001 From: katspaugh Date: Sun, 15 Oct 2023 13:00:19 +0200 Subject: [PATCH] Fix: isPlaying() should return true directly after play() --- cypress/e2e/basic.cy.js | 14 ++++++++++++++ src/player.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/basic.cy.js b/cypress/e2e/basic.cy.js index 202e7594c..447ed5911 100644 --- a/cypress/e2e/basic.cy.js +++ b/cypress/e2e/basic.cy.js @@ -185,4 +185,18 @@ describe('WaveSurfer basic tests', () => { expect(win.wavesurfer.getMediaElement().id).to.equal('new-media') }) }) + + it('should return true when calling isPlaying() after play()', (done) => { + cy.window().then((win) => { + expect(win.wavesurfer.isPlaying()).to.be.false + win.wavesurfer.play() + expect(win.wavesurfer.isPlaying()).to.be.true + win.wavesurfer.once('play', () => { + expect(win.wavesurfer.isPlaying()).to.be.true + win.wavesurfer.pause() + expect(win.wavesurfer.isPlaying()).to.be.false + done() + }) + }) + }) }) diff --git a/src/player.ts b/src/player.ts index 081c846db..114d1ca58 100644 --- a/src/player.ts +++ b/src/player.ts @@ -95,7 +95,7 @@ class Player extends EventEmitter { /** Check if the audio is playing */ public isPlaying(): boolean { - return this.media.currentTime > 0 && !this.media.paused && !this.media.ended + return !this.media.paused && !this.media.ended } /** Jumpt to a specific time in the audio (in seconds) */