question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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;  }
}

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
HilmiZulcommented, Mar 23, 2019

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?

0reactions
Brahvimcommented, Jun 17, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

AVPlayer can't resume after paused + some waiting
play() ok it continues but if I wait 30-60 sec after .pause() and try to .play() it sometimes fail to play,. AVPlayerStatus.Failed returns...
Read more >
526411 - after pausing a video it often won't restart playing later
When the video is stuck, I can issue .load() and it successfully restarts ... local files will still not play again after pressing...
Read more >
Pausing and Resuming an Activity | Android Developers
As your activity enters the paused state, the system calls the onPause() method on your Activity , which allows you to stop ongoing...
Read more >
IMediaControl::Run method (control.h) - Win32 - Microsoft Learn
Therefore, if you run the graph, pause it, and then run it again, playback resumes from the paused position. If you run the...
Read more >
Play, from paused, jumps to the start for no reason
This happens to me frequently; imagine I'm working my way through an audio document, I pause the playback for some reason, if I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found