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

118
Views
Range and video are confronting

I am writing a video player. As a timebar I use a range. As video is playing, range is changing too. But I want to change it in the opposite way. I want range make video change its currentTime. But, because they change each other, I can't move a thumb. I'd tried setting Interval null but it didn't work. Give me a hand with this, please.

$(document).ready( function () {
$("#PlayerVideo").on("loadedmetadata", function (event) {
            Video = $("#PlayerVideo")[0];
            
            Duration = Video.duration;
            hours = Math.floor(Duration / 60 / 60);
            mins = Math.floor((Duration - hours * 60 * 60) / 60);
            secs = Math.floor(Duration - mins * 60);
            $("#durTime").html(hours + ":" + mins + ":" + secs);
            
            
            // display cur time 
            Interval = setInterval(
                function () {
                    Play();
                }, 250
            );
        });     

        $("#TimeRange").on("input",
            function()
            {
                $.when().then(
                    function()
                    {
                        Interval = null;
                    }
                ).then(
                    function ()
                    {
                        Video = $("#PlayerVideo")[0];
                        Video.currentTime = $(this).val()*Duration;
                        console.log("cur time is " + Video.currentTime);
                        CurTime = $(this).val()*Duration;
                    }
                ).then(
                    function ()
                    {
                        Interval = setInterval(
                            function () {
                                Play();
                            }, 250
                        );
                    }
                );    
            }
        );

        function Play()
        {
            Video = $("#PlayerVideo")[0];
            CurTime = Video.currentTime;
            console.log(CurTime);
            hours = Math.floor(CurTime / 60 / 60);
            mins = Math.floor((CurTime - hours * 60 * 60) / 60);
            secs = Math.floor(CurTime - mins * 60);
            $("#curTime").html(hours + ":" + mins + ":" + secs);
            $("#TimeRange").val(CurTime / duration * 100);
        }
});

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Try adding $(this).trigger('change'); just after you are calling Play() and remove $("#TimeRange").val(CurTime / duration * 100);

about 4 years ago · Santiago Gelvez Report

0

I changed $(this) to $("#TimeRange"). And added division by 100 when setting a new value.

about 4 years ago · Santiago Gelvez 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!