Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
Sequential Events on JavaScript for on Function

For video player, there are 3 actions: play, pause and continue. For continue action, it is defined as play after being pause.

If I have 2 functions already defined for play and pause:

videoPlayer.on('play', function () {
      //play video
});
videoPlayer.on('pause', function () {
      //pause video
});

I am having trouble defining the sequential action of pause -> play. Would the below function work for continue?

videoPlayer.on('pause').on('play', function () {
       //Continue video           
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I understood your question correctly, you could use promises to wait till the video is paused

function playP() {
    videoPlayer.on('play', function () {
        //play video
    });
}

function pauseP() {
    return new Promise((res, rej) => {
        videoPlayer.on('pause', function () {
            // do stuff
            res(true);
        });
    })
}

pauseP().then((x) => {
    if (x) 
        playP();
})

This code will wait till the video is paused to start listening for the play event.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!