p5.js-sound icon indicating copy to clipboard operation
p5.js-sound copied to clipboard

After .pause(), .play() does NOT resume from the paused position but from an earlier point

Open BS-007 opened this issue 7 years ago • 9 comments

Concerns: https://p5js.org/reference/#/p5.SoundFile/pause OS: Windows 7 Browser: Firefox Quantum 57.02 (64 bits) p5.js v0.5.16

let bPlay = true;
let sndFile;
 
function preload() 
{
  sndFile = loadSound('Sound/D960_3.mp3');
}
 
function setup() 
{
  sndFile.play();
}
 
function mousePressed()
{
  if (bPlay) { sndFile.pause(); bPlay=false; }
  else       { sndFile.play();  bPlay=true;  }
}

BS-007 avatar Dec 17 '17 15:12 BS-007

I'm trying this, it's work..

if (!pause) {
  pause = true;
  music.pause();
} else {
  pause = false;
  music.play();
}

p5 v 0.6.0 google chr 73.0

HilmiZul avatar Mar 22 '19 12:03 HilmiZul

Also, the current version of p5 is 0.7.3.

dirkk0 avatar Mar 22 '19 15:03 dirkk0

&HilmiZul and @dirkk0: Thanks for your reactions. Dirk Krause: I now use p5 0.7.3 of course, and Firefox 66.01. Zul Hilmi: I inserted your code. It often works as it is described in the reference. But sometimes (1 in 5 times) it resumes from an earlier position, often from the beginning. I tried it on Windows 7 and on a brand new system with Windows 10. With several mp3 files. Always the same problem.

`// BS_P5_0272 : Loading soundfile in preload() // loadSound(): https://p5js.org/reference/#/p5.SoundFile/loadSound // play() : https://p5js.org/reference/#/p5.SoundFile/play // pause() : https://p5js.org/reference/#/p5.SoundFile/pause

// p5: 0.7.3 // Firefox: 66.01

// After .pause(), .play() does NOT resume from the paused position // but from an earlier point

let pause = false; let music;

function preload() { music = loadSound('Music.mp3'); }

function setup() { createCanvas(600, 400); music.play(); }

function draw() { background(150); if (!pause) text("Click the mouse to stop", 30, 200); else text("Click the mouse to play", 30, 200); }

function mousePressed() { if (!pause) { pause = true; music.pause(); } else { pause = false; music.play(); } }`

BS-007 avatar Mar 22 '19 21:03 BS-007

change the let pause = false value to true. remove music.play(); in setup() function, if you want to control using mousePressed.

full code:

let pause = true;
let music;

function preload() {
  music = loadSound('Music.mp3');
}

function setup() {
  createCanvas(600, 400); 
}

function draw() {
  background(150);
  if (!pause) {
    text("Click the mouse to stop", 30, 200);
  } else {
    text("Click the mouse to play", 30, 200);
  }
}

function mousePressed() {
  if (!pause) {
    pause = true;
    music.pause();
  } else {
    pause = false;
    music.play();
  }
}

btw, have you tried using Google Chrome?

HilmiZul avatar Mar 23 '19 01:03 HilmiZul

@HilmiZul :+1: Thanks for your persistence. I copied your version but the same error occurs. The first five or six times it works OK. After that it jumps back to the beginning.

I have not tried Chrome, but I very much want it to work in Mozilla. For now I have stopped working with sound.

BTW: your videos on YouTube deserve English subs.

BS-007 avatar Mar 23 '19 17:03 BS-007

Same Problem! Even in 2021...

Brahvim avatar Jun 05 '21 09:06 Brahvim

@Brahvim : Thank you very much Brahvim! I thought I had gone crazy. The error keeps returning, even with the latest versions of everything. I guess the focus of the p5 team is elsewhere. Thanks again.

BS-007 avatar Jun 06 '21 16:06 BS-007

@Brahvim : Thank you very much Brahvim! I thought I had gone crazy.

The error keeps returning, even with the latest versions of everything.

I guess the focus of the p5 team is elsewhere. So far I have posted three comments (if I remember correctly).

But non of them were recognized (except by you)

or even appreciated.

Probably the emphasis on inclusion does not include me.

That makes me a little sad. Thanks again. Op za., jun. 5, 2021 om 11:25, Brahvim schreef: Same Problem! Even in 2021... — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub (https://github.com/processing/p5.js-sound/issues/235#issuecomment-855211759), or unsubscribe (https://github.com/notifications/unsubscribe-auth/AEXLNNRV33F34IFLS53BCY3TRHUO3ANCNFSM4EISZWXA).

BS-007 avatar Jun 06 '21 16:06 BS-007

No need to thank me @BS-007 ":]

Brahvim avatar Jun 17 '21 06:06 Brahvim