fregante / iphone-inline-video

📱 Make videos playable inline on the iPhone (prevents automatic fullscreen)
https://npm.im/iphone-inline-video
MIT License
2.05k stars 300 forks source link

Cannot get the video to jump to different currentTime #121

Closed DieterPagel closed 7 years ago

DieterPagel commented 7 years ago

First off, thanks for this excellent working example! We've had a nightmare trying to get videos to play inline on iPhones.

We are now however struggling to get the video to jump to a certain predetermined point by setting the currentTime on a click event (Using Video.js). Let's say that when you click on the Play button to start the video, it must start the video 15 seconds into the video. Setting myPlayer.currentTime(15) and then running myPlayer.play() just starts the video from the start each time. Any suggestions?

fregante commented 7 years ago

Can you try accessing the video directly instead of using video.js? What happens when you run:

// video = myPlayer.el; // I think
video.currentTime = 15;
video.play();

Alternatively, try doing it in the opposite order:

video.play();
video.currentTime = 15;
DieterPagel commented 7 years ago

We've tried that and neither seems to work. It just starts at the beginning of the video each time. It seems the answer generally revolves around this link: https://stackoverflow.com/questions/18266437/html5-video-currenttime-not-setting-properly-on-iphone We're going to play around with that a bit now and see if we can make any progress

fregante commented 7 years ago

Ah, what is the value of video.duration before you try setting the time? If it's 0, that is indeed the reason. The solution is to have the browser load the metadata first like described in that link.

Also, make sure you really need to have a video that starts 15 seconds later instead of using a file that starts at the right time. Seeking is always messy

DieterPagel commented 7 years ago

We managed to find this link that provides a full working solution to many aspects of the video properties we require: https://www.w3.org/2010/05/video/mediaevents.html. We've tweaked it to allow inlineplay so I think we're pretty much there.

Thanks again for your working solution and prompt responses!