How to play video from google drive using javascri

2019-01-29 00:04发布

How to play video from google drive using javascript?

It does not work, how can I do that?

http://fiddle.jshell.net/gt4otyfk/1/

<script type="text/javascript">
    $(function(){
        var video = $("#video").get(0);
        video.controls = true;
        $("#play").click(function() {
            video.play();
        });
    });
</script>

2条回答
The star\"
2楼-- · 2019-01-29 00:08

Google provides some GET-params like export and id with google-drive:

?export=download&id=YOUR_LONG_VIDEO_ID

to give you the ability to insert an uploaded video into a HTML5-video-tag.

This should work:

$("#play").click(function() {
   $("#video")[0].play();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button id="play" style="margin-top: 300px;">Play</button>

<video id="video" width="320" height="240" controls>
   <source src="https://drive.google.com/uc?export=download&id=0B8-qLYDzDfCyRF9vOE9sWmx5YjA" type='video/mp4'>
   Your browser does not support the video tag.
</video> 

Just press "Run code snippet"-button to run this example. Hope this helps.

查看更多
老娘就宠你
3楼-- · 2019-01-29 00:12

Just use the preview link you see on your URL when you open/play your video from your Google Drive: Be sure to include

sandbox="allow-same-origin allow-scripts allow-popups allow-forms"

  <body>
       <iframe sandbox="allow-same-origin allow-scripts allow-popups allow-forms" width="560" height="315" src="https://drive.google.com/file/d/0Bzgk4zccNwI7QkNZRnpBdExHOUk/preview?autoplay=1" frameborder="0" allowfullscreen></iframe>​
  </body>

Got it working:

enter image description here

查看更多
登录 后发表回答