p5.js-sound
p5.js-sound copied to clipboard
After .pause(), .play() does NOT resume from the paused position but from an earlier point
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; }
}
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
Also, the current version of p5 is 0.7.3.
&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(); } }`
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 :+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.
Same Problem! Even in 2021...
@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.
@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).
No need to thank me @BS-007 ":]