Does anyone know if there is a way to use dynamic content with the Video.js plugin so users can toggle auto-play on/off?
I’m not sure that’s possible with the plugin, but you can use normal code in an HTML element instead which gives you more control. Below is the Video.js source code, just copy/paste it in You’ll want to change the Poster (probably just delete the line altogether) and then change the source src = to be the dynamic URL of your video. Notice it says ‘autoplay’ in the list within the video tag, that means it’s enabled. So have a condition on the html element linked to your toggle and copy/paste the code below into the conditional HTML and remove the ‘autoplay’ line for when your user wants it disabled. Hope that helps!
<head>
<link href="https://vjs.zencdn.net/7.10.2/video-js.css" rel="stylesheet" />
<!-- If you'd like to support IE8 (for Video.js versions prior to v7) -->
<!-- <script src="https://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"></script> -->
</head>
<body>
<video
id="my-video"
class="video-js"
controls
preload="auto"
width="640"
height="264"
poster="MY_VIDEO_POSTER.jpg"
autoplay
data-setup="{}"
>
<source src="MY_VIDEO.mp4" type="video/mp4" />
<source src="MY_VIDEO.webm" type="video/webm" />
<p class="vjs-no-js">
To view this video please enable JavaScript, and consider upgrading to a
web browser that
<a href="https://videojs.com/html5-video-support/" target="_blank"
>supports HTML5 video</a
>
</p>
</video>
<script src="https://vjs.zencdn.net/7.10.2/video.min.js"></script>
</body>
@help, thanks for the reply on this. The HTML portion worked.
Because I’m wanting some other features though, I’m planning to go with the VideoJS Advanced plugin from @pork1977gm with its nifty features.