I am trying to start playing a video.js player instance programmatically by using the play()
method on it.
The markup for the player is as follows:
<video-js id ="some-player-id"
src ="https://vjs.zencdn.net/v/oceans.mp4"
class="VideoPlayer">
</video-js>
According to the documentation, I should be able to create the player using the element's id
and then call play()
to start playback...
// Initialize player instance
const player = videojs.getPlayer("some-player-id");
// Start playback when ready
player.ready(function() {
player.play()
});
However, I am facing some issues with this approach and would like to understand why. Please refer to the attached snippet for more information.
// Initialize player instance
const player = videojs("some-player-id");
// Start playback when ready
player.ready(function() {
player.play();
});
<link href="https://vjs.zencdn.net/7.20.1/video-js.css" rel="stylesheet"/>
<div class="VideoPlayer">
<video-js id ="some-player-id"
src ="https://vjs.zencdn.net/v/oceans.mp4"
class="VideoPlayer__videoJs">
</video-js>
</div>
<script src="https://vjs.zencdn.net/7.20.1/video.min.js"></script>