教程集 www.jiaochengji.com
教程集 >  前端编程  >  HTML5教程  >  正文 Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧

Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧

发布时间:2020-05-17   编辑:jiaochengji.com
教程集为您提供Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧等资源,欢迎您收藏本站,我们将为您提供最新的Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧资源
这篇文章主要介绍了Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧的相关资料,有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助。

本文介绍了Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧,分享给大家,具体如下:

1.jpg

当一收到上传图片视频并可以动态设置视频显示的海报帧的需求时,主要想的是怎么样解析视频并获取保存每帧的图片,百度出来的大多是类似下面这种需要播放video并点击截图的,或者是用php ffmpeg扩展,跟需求不一致,有点抓狂了,然后就先做了视频图片的预览功能,进而对设置海报帧换了种思路,通过输入设置video开始播放的时间,取消自动播放和控制条,这样用户看到的就是一张图片

 /*预览*/
              
$('.qtuploader__items').on('click', '[name="viewVideoPicBtn"]', function() {
    var parent = $(this).closest('.qtab__page');
    var video = $(this).closest('.qtuploader__itemsbd').find('video');
    var srcStr = '', htmlStr = '';
    if($(this).siblings('.qtuploader__picinputbox').hasClass('is-error')){
      $.fn.toast({
        'parentDom': parent,
        'classes': 'isorange',
        'top': '0',
        'spacing': 0,
        'toastContent': '请设置正确范围的海报帧',
        'autoHide': 3000,
        'position': {
          'top': '5px',
          'left': '50%'
        }
      });
      return;
    }
    if (video.length > 0) {
      var thumbHeight = setSize(video)[0];
      var thumbWidth = setSize(video)[1];
      srcStr = video.attr('src');
      htmlStr = '<p class="qtuploader__view"><p class="qtuploader__mask"></p><p class="qtuploader__thumb" style="width:'   thumbWidth   'px;height:'   thumbHeight   'px;margin:0 auto;"><video controls width="'   thumbWidth   '" height="'   thumbHeight   '" src="'   srcStr   '">您的浏览器不支持 video 标签</video></p></p>';
    }
    parent.append(htmlStr);
    parent.find('.qtuploader__view video')[0].currentTime = $(this).siblings('.qtuploader__picinputbox').find('.qtuploader__picinput').val();
    parent.find('.qtuploader__view').fadeIn();
  });
  
  /*设置海报帧预览时间*/
  $('.qtuploader__items').on('keyup', '.qtuploader__picinput', function() {
    var parent = $(this).closest('.qtuploader__picinputbox');
    var video = $(this).closest('.qtuploader__itemsbd').find('video');
    var strVal = $.trim($(this).val());
    console.log(strVal)
    if (strVal == '') {
      parent.addClass('is-error');
      parent.find('.qverify__font').text('请设置海报帧');
    } else if (!(/^[0-9]*$/.test(strVal))) {
      parent.addClass('is-error');
      parent.find('.qverify__font').text('请输入数字');
    } else if (video.length > 0 && strVal > video[0].duration) {
      parent.addClass('is-error');
      parent.find('.qverify__font').text('不超过('   video[0].duration   ')');
      console.log('111---'   video[0].duration)
    } else {
      parent.removeClass('is-error');
      parent.find('.qverify__font').text('请设置海报帧');
    }
  })
  /*关闭预览*/
  $(document).undelegate('.qtuploader__mask', 'click');
  $(document).delegate('.qtuploader__mask', 'click', function() {
    $(this).closest('.qtuploader__view').fadeOut('normal', function() {
      $(this).closest('.qtuploader__view').remove();
    })
  })
  /*设置预览大小*/
  function setSize(element) {
    var thumbWidth = 0, thumbHeight = 0, arr = [];
    var winWidth = $(window).width(), winHeight = $(window).height();
    var imgWidth = element.width(), imgHeight = element.height();
    if (imgWidth > imgHeight) {
      thumbHeight = parseInt(winHeight - 200);
      thumbWidth = parseInt((1920 * thumbHeight) / 1080);
    } else {
      thumbHeight = parseInt(winHeight - 200);
      thumbWidth = parseInt((1080 * thumbHeight) / 1920);
    }
    arr.push(thumbHeight, thumbWidth)
    return arr;
  }

总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。更多相关教程请访问Html5视频教程!

相关推荐:

php公益培训视频教程

HTML5图文教程

HTML5在线手册

以上就是Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧的详细内容,更多请关注教程集其它相关文章!

  • 本文转载于:脚本之家,如有侵犯,请联系jquerycn@qq.com删除
  • 您可能感兴趣的文章:
    Html5 video 上传预览图片视频,设置、预览视频某秒的海报帧
    HTML5中video标签如何使用
    html5播放视频的标签是什么?如何在web页面播放视频呢?(内附实例)
    HTML5音频与视频问题及解决方法
    html5的video(视频)和audio(音频)标签中的属性用法
    关于html5中标签video播放的新解析
    html5中video标签的详细介绍
    canvas与h5如何实现视频截图功能
    如何在网站头部添加视频海报?添加视频海报的方法(代码示例)
    HTML5嵌入音频和视频的方法

    [关闭]
    ~ ~