Video.js and Vue integration

Here’s a basic Vue player implementation.

It just instantiates the Video.js player on mounted and destroys it on beforeDestroy.

  1. <template>
  2. <div>
  3. <video ref="videoPlayer" class="video-js"></video>
  4. </div>
  5. </template>
  6. <script>
  7. import videojs from 'video.js';
  8. export default {
  9. name: "VideoPlayer",
  10. props: {
  11. options: {
  12. type: Object,
  13. default() {
  14. return {};
  15. }
  16. }
  17. },
  18. data() {
  19. return {
  20. player: null
  21. }
  22. },
  23. mounted() {
  24. this.player = videojs(this.$refs.videoPlayer, this.options, function onPlayerReady() {
  25. console.log('onPlayerReady', this);
  26. })
  27. },
  28. beforeDestroy() {
  29. if (this.player) {
  30. this.player.dispose()
  31. }
  32. }
  33. }
  34. </script>

You can then use it like this: (see options guide for option information)

  1. <template>
  2. <div>
  3. <video-player :options="videoOptions"/>
  4. </div>
  5. </template>
  6. <script>
  7. import VideoPlayer from "@/components/VideoPlayer.vue";
  8. export default {
  9. name: "VideoExample",
  10. components: {
  11. VideoPlayer
  12. },
  13. data() {
  14. return {
  15. videoOptions: {
  16. autoplay: true,
  17. controls: true,
  18. sources: [
  19. {
  20. src:
  21. "/path/to/video.mp4",
  22. type: "video/mp4"
  23. }
  24. ]
  25. }
  26. };
  27. }
  28. };

Don’t forget to include the Video.js CSS, located at video.js/dist/video-js.css.