zoukankan      html  css  js  c++  java
  • H5上传前预览视频(结合 video标签 &&h5 fileApi)

    2017/09/14 发布

    js代码:

    // hTML5实现表单内的上传文件框,上传前预览视频,刷新预览video,使用HTML5 的File API,
    // 建立一个可存取到该file的url,一个空的video标签,ID为video0,把选择的文件显示在video标签中,实现视频预览功能。
    // 需要选择支持HTML API的浏览器。
             $("#video").change(function(){
                 var objUrl = getObjectURL(this.files[0]) ;
                 console.log("objUrl = "+objUrl) ;
                 if (objUrl) {
                     $("#video0").attr("src", objUrl) ;
                 }
             }) ;
             //建立一个可存取到该file的url
             function getObjectURL(file) {
                 var url = null ;
                 if (window.createObjectURL!=undefined) { // basic
                     url = window.createObjectURL(file) ;
                 } else if (window.URL!=undefined) { // mozilla(firefox)
                     url = window.URL.createObjectURL(file) ;
                 } else if (window.webkitURL!=undefined) { // webkit or chrome
                     url = window.webkitURL.createObjectURL(file) ;
                 }
                 return url ;
             }

    html:

    <video style="height:auto;" src="" id="video0" controls="controls"></video>
    <input class="form-control" type="file" style="height:auto;"
    id="video" name="video"/>
  • 相关阅读:
    《Dive into Python》Study_Notes
    Python 各种应用收集
    Remotely disconnect a terminal services session
    stop the bibi
    SQL写法(累积)
    Django’s admin html editor — TinyMCE
    Djangobook note
    清除windows系统垃圾
    ubuntu下PDF乱码解决方法
    using的几种用法
  • 原文地址:https://www.cnblogs.com/mithrandirw/p/8468867.html
Copyright © 2011-2022 走看看