带有参数的HTML5视频自动播放

时间:2015-09-27 18:25:39

标签: html5 video autoplay

如何使用URL中的param播放HTML5视频自动播放?

例如:http://mydomain/video?autoplay=1

html5视频是否可能?

我知道:HTML5标签,

1 个答案:

答案 0 :(得分:2)

您可以使用autoplay

来实现这一目标
 <video controls autoplay>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video> 

如果你想获得autoplay的参数,让我们说,用php,你可以使用:

url:http://mydomain/video.php?autoplay=1

<强> video.php

<?php
$autoplay = "";
if($_GET['autoplay'] === "1"){

   $autoplay = "autoplay";
}

//now we can serve the video

$html5Video = <<< LOL
 <video controls $autoplay>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video> 
LOL;
echo $html5Video;

?>

注意: 大多数移动浏览器上的html5视频autoplay isn't supported