This presents a major limitation for advertisers since video ads are not clickable and overlay ads cannot be displayed.
Any custom user interaction during video playback is not supported which prevents interactive videos and games.
There are few approaches for a solution, and here is mine, which I hope you find helpful.
Demo (open on an iPhone): http://amirch1.github.io/VideoInline/
Github code under MIT license: https://github.com/amirch1/VideoInline
The solution:
- Create an Audio tag and give it the source of the Video tag. Audio tags support any video format (mp4, m3u8 HLS streams, live) and play inline.
- Hide the Video tag native controls using Shadow DOM CSS rules.
- Add custom Play / Pause button and a progress bar.
- Clicking the Play button triggers the Audio tag play() method. It also invokes the Video tag load() method which enables video seek operation.
- A timed interval is set to sync the Video tag currentTime property to the Audio tag currentTime property. The time interval actually defines the playback frame rate enabling balance between quality and performances. It also updates the progress bar.
- Seeking using the progress bar sets the Audio tag currentTime value. The Video tag updates accordingly by the timer refresh.
Thats it!
Rather simple, provides real audio sync and supports all video formats including mp4, HLS and live streams.
Can be easily enhanced to support fullscreen playback without loosing interactivity and additional video controls.
Feel free to play with the code, submit pull requests and star the Github repository :)
That is awesome! Is there a way to make it autoplay and loop?
ReplyDelete