简体   繁体   中英

hls.js currentTime not working how to start video from x seconds

i've been trying to make a html5 player to play m3u8 files but i want to start from x seconds but its not working.

 <html> <head> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.2/jquery.min.js'></script> <script src="https://cdn.jsdelivr.net/hls.js/latest/hls.min.js"></script> </head> <body> <video id="video" width="100%" autoplay height="100%" controls class="player"> <track src="subtitles" label="English" kind="subtitles" srclang="en" default> </video> <script> var video = document.getElementById('video'); var startTime = 55; if(Hls.isSupported()) { var hls = new Hls(); hls.loadSource('https://vz-f68ee764-984.b-cdn.net/73e38955-bf02-4129-84b8-981f596a5fe0/3840x2160/video.m3u8'); hls.attachMedia(video); hls.on(Hls.Events.MANIFEST_PARSED,function() { video.play(); video.currentTime = startTime; }); } </script> </body> </html>

To start the video from a specific time you can put in the config object:\

const config = {
 startPosition: 10 // can be any number you want
}

const HLS = new Hls(config);

Check this link: HLS.js doc
And also: this one

There is another way to do that:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM