您当前位置:首页 > 文章中心 > HTML5+CSS3 > HTML5

html5视频播放器

稿件来源: 互联网   撰稿作者: 太阳光   发表日期: 2013-10-04   阅读次数: 300   查看权限: 游客查看

html5视频播放器代码

属性 描述
autoplay autoplay 如果出现该属性,则视频在就绪后马上播放。
controls controls 如果出现该属性,则向用户显示控件,比如播放按钮。
height pixels 设置视频播放器的高度。
loop loop 如果出现该属性,则当媒介文件完成播放后再次开始播放。
preload preload

如果出现该属性,则视频在页面加载时进行加载,并预备播放。

如果使用 "autoplay",则忽略该属性。

src url 要播放的视频的 URL。
width pixels 设置视频播放器的宽度。

下面列出了大多数浏览器支持的视频方法、属性和事件:

方法 属性 事件
play() currentSrc play
pause() currentTime pause
load() videoWidth progress
canPlayType videoHeight error
  duration timeupdate
  ended ended
  error abort
  paused empty
  muted emptied
  seeking waiting
  volume loadedmetadata
  height  
  width  
<!DOCTYPE html>
<html>
<head> 
<meta charset=utf-8> 
<title>HTML5视频教程-视频播放功能</title>
</head>
<body>
<video id="scscms" width="600" height="350" src="http://down.scscms.com/html5/video/mp4.mp4" controls="controls" poster="http://down.scscms.com/html5/video/poster.jpg">你的浏览器不支持html5器</video>
<button type="button" title="play">播放</button>
<button type="button" title="pause">暂停</button>
<button type="button" title="speed">快进10秒</button>
<button type="button" title="reverse">快退10秒</button>
<button type="button" title="add_speed">播放速度+</button>
<button type="button" title="reduce_speed">播放速度-</button>
<button type="button" title="add_vol">声音+</button>
<button type="button" title="reduce_vol">声音-</button>
<button type="button" title="muted_true">静音</button>
<button type="button" title="muted_false">解除静音</button>
<button type="button" title="full">全屏</button>
<script type="text/javascript">
    window.onload=function(){
        var video=document.getElementById("scscms");
        var button=document.getElementsByTagName("button");
        var obj={
            play:function(){video.play()},
            pause:function(){video.pause()},
            speed:function(){video.currentTime+=10},
            reverse:function(){video.currentTime-=10},
            add_speed:function(){video.playbackRate+=2},
            reduce_speed:function(){video.playbackRate-=2},
            add_vol:function(){video.volume<1?video.volume+=0.1:""},//音量范围是0-1
            reduce_vol:function(){video.volume>0.2?video.volume-=0.1:""},
            muted_true:function(){video.muted=true},
            muted_false:function(){video.muted=false},
            full:function(){
                video.webkitEnterFullscreen(); // webkit类型的浏览器
                video.mozRequestFullScreen();  // FireFox浏览器
            }
        };
        for(var i= button.length-1;i>=0;i--){
            button[i].onclick=function(){
                console.log(video.volume);
                obj[this.title]();
            }
        }
    };
</script>
</body>
</html> 

关键词: html5,video,视频播放器   编辑时间: 2013-10-04 22:50:40

  • 感到高兴

    0

    高兴
  • 感到支持

    0

    支持
  • 感到搞笑

    0

    搞笑
  • 感到不解

    0

    不解
  • 感到谎言

    0

    谎言
  • 感到枪稿

    0

    枪稿
  • 感到震惊

    0

    震惊
  • 感到无奈

    0

    无奈
  • 感到无聊

    0

    无聊
  • 感到反对

    0

    反对
  • 感到愤怒

    0

    愤怒
100%(1)
0%(0)
共有0 条评论 发言请遵守【相关规定

网友评论

会员头像
发 表同步腾讯微博    验证码:  点击更新请先登陆
  • 暂无评论
关闭模块文章图片 article Pictrue
  • 我的妈妈爸爸
  • 基于koa2+mysql+vue2.0+Element阳光内容管理系统
  • 代码覆盖率工具 Istanbul 入门教程
  • 全栈工程师的武器——MEAN
  • 9款超炫的 CSS3 复选框(Checkbox)
  • 微信开发在线翻译功能
  • CSS3那些不为人知的高级属性
  • 给easyui的datebox添加清空事件
  • flash写字效果
  • kendoUI系列教程之DropDownList下拉菜单
  • kendoUI系列教程之datetimepicker日期时间选择
  • kendoUI系列教程之datepicker日期选择
  • kendoUI系列教程之combobox下拉列表框
  • kendoUI系列教程之colorpicker
  • kendoUI系列教程之calendar日历表
  • kendoUI系列教程之autocomplete自动补齐