Search code examples
javascripthtmliframeyoutube-apigoogle-drive-api

How to embed videos from Google drive to webpage?


I'm trying to load a video on a web page and for YouTube embed code it works. However, when I replace the src in the code with a Google Drive Link of a video (with sharing turned on), nothing comes up. I mean, there is no error but its blank. Why does nothing come up here? How can I get this Google drive video to also to load on my webpage? I dont want to have to paste the url manually in chrome.

THIS DOES NOTHING:

<html>
<head>
</head>
<body>
<iframe width="100%" height="100%" src="https://drive.google.com/file/d/1pdvh_mEnkXPKA3jivYIpYKTaoukxH5p3Yg/view?usp=sharing"></iframe>
</body>
</html>

The YouTube version works perfectly:

<html>
<head>
</head>
<body>
<iframe width="100%" height="100%" src="https://www.youtube.com/embed/UTt33udwRw0" frameborder="0" allowfullscreen></iframe>
</body>
</html>

How do I get the video from Google drive to play on my web page like how the YouTube video plays? If it cant be directly embedded - what alternatives can be used to get the video to appear - iframe is clearly not working, there must be some alternatives.

Also, anyone know how to make it autoplay?

Thanks


Solution

  • EDIT: September 2022

    It seems at some point since this answer was first posted, autoplaying has stopped working. As it currently stands, the video player attempts to autoplay but fails to load, indicating that this is probably a bug. I've not yet found a suitable alternative.

    Original Answer

    You need to use the Google Drive Embed option. This is the URL you are looking for: https://drive.google.com/file/d/1pdvh_mEnkXPKA3jivYIpYKTaoukxH5p3Yg/preview

    <html>
    <head>
    </head>
    <body>
    <iframe width="100%" height="100%" src="https://drive.google.com/file/d/1pdvh_mEnkXPKA3jivYIpYKTaoukxH5p3Yg/preview"></iframe>
    </body>
    </html>
    

    You can make it autoplay by appending ?autoplay=1 to the URL so it is now https://drive.google.com/file/d/1pdvh_mEnkXPKA3jivYIpYKTaoukxH5p3Yg/preview?autoplay=1.