0

I can run video with link embed youtube.

My code:

<video id='my-video' class='video-js' controls preload='auto' width='640' height='264'
    poster='' data-setup='{}'>
      <source src='https://www.youtube.com/embed/fZ-yXDJJj5g'>
      <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>

Video is show loading but don't play.
Please help me

Huan Ho
  • 145
  • 2
  • 9
  • Have you thought about using the `youtube API` player? Also `https://www.youtube.com/embed/fZ-yXDJJj5g` is a player not a video source so this could be why it isn't playing as expected. – NewToJS May 11 '19 at 16:54
  • If you want to keep using `video-js` then maybe this might be of some help [**GitHub videojs-youtube**](https://github.com/videojs/videojs-youtube) I decided to do a quick search in relation to your question and found that so I haven't tested it for myself. – NewToJS May 11 '19 at 17:00

3 Answers3

1

As stated on the official repo, video.js doesn't support youtube video out of the box, you need to use a plugin for that:

It supports HTML5 and Flash video, as well as YouTube and Vimeo (through plugins)

So you'll have to use a plugin for that, like for example this one.

Julien
  • 2,217
  • 2
  • 28
  • 49
0

HTML5's video tag only works with video files. It doesn't work with Youtube video links(As those links do not point to source of video, instead they are a pointer to an HTML page). For that either you have to find storage link of video, which is not a good practice. Because Youtube can change that anytime. Better to use iframe for displaying Youtube video on your website.

Zaid Afzal
  • 362
  • 2
  • 7
0

You could just use tag then pass the src of the video. or even embed just like this.

<iframe id='my-video' class='video-js' width="640" height="264" src="https://www.youtube.com/embed/fZ-yXDJJj5g">
</iframe>

or

<embed id='my-video' class='video-js' width="640" height="264"
src="https://www.youtube.com/v/tgbNymZ7vqY">

then target those id to perform whatever you wanted to do.

I've encountered this problem, video tag does not work on this scenario. So, I've research you can use iframe tag or embed then play with it into the script.

Paulynz
  • 1
  • 1
  • 1
    I think the OP wants to use the `video-js` to play the `youtube` video. I don't know if adding the `id` and `class` to the `iframe` will enable that? – NewToJS May 11 '19 at 17:02