Home Web Front-end H5 Tutorial Html5 video upload preview image video, set and preview the poster frame of a certain second of the video

Html5 video upload preview image video, set and preview the poster frame of a certain second of the video

Oct 09, 2018 pm 03:47 PM
html5 video Upload video

This article mainly introduces the relevant information of Html5 video uploading preview image video, setting and previewing the poster frame of a certain second of the video. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

This article introduces Html5 video to upload preview image video, set and preview the poster frame of a certain second of the video, and share it with everyone. The details are as follows:

Html5 video upload preview image video, set and preview the poster frame of a certain second of the video

## When a When receiving the request to upload pictures and videos and dynamically set poster frames for video display, the main thing I thought about was how to parse the video and obtain and save the pictures of each frame. Most of the ones produced by Baidu are similar to the one below that requires playing the video and clicking on the screenshot. , or use the php ffmpeg extension, which is inconsistent with the requirements, and I am a little crazy. Then I first made a preview function of the video picture, and then changed the idea of ​​setting the poster frame. I set the time when the video starts playing by inputting it, and canceled the automatic playback. and control bar, so that what the user sees is a picture

 /*预览*/
              
$('.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 = &#39;<p class="qtuploader__view"><p class="qtuploader__mask"></p><p class="qtuploader__thumb" style="width:&#39; + thumbWidth + &#39;px;height:&#39; + thumbHeight + &#39;px;margin:0 auto;"><video controls width="&#39; + thumbWidth + &#39;" height="&#39; + thumbHeight + &#39;" src="&#39; + srcStr + &#39;">您的浏览器不支持 video 标签</video></p></p>&#39;;
    }
    parent.append(htmlStr);
    parent.find(&#39;.qtuploader__view video&#39;)[0].currentTime = $(this).siblings(&#39;.qtuploader__picinputbox&#39;).find(&#39;.qtuploader__picinput&#39;).val();
    parent.find(&#39;.qtuploader__view&#39;).fadeIn();
  });
  
  /*设置海报帧预览时间*/
  $(&#39;.qtuploader__items&#39;).on(&#39;keyup&#39;, &#39;.qtuploader__picinput&#39;, function() {
    var parent = $(this).closest(&#39;.qtuploader__picinputbox&#39;);
    var video = $(this).closest(&#39;.qtuploader__itemsbd&#39;).find(&#39;video&#39;);
    var strVal = $.trim($(this).val());
    console.log(strVal)
    if (strVal == &#39;&#39;) {
      parent.addClass(&#39;is-error&#39;);
      parent.find(&#39;.qverify__font&#39;).text(&#39;请设置海报帧&#39;);
    } else if (!(/^[0-9]*$/.test(strVal))) {
      parent.addClass(&#39;is-error&#39;);
      parent.find(&#39;.qverify__font&#39;).text(&#39;请输入数字&#39;);
    } else if (video.length > 0 && strVal > video[0].duration) {
      parent.addClass(&#39;is-error&#39;);
      parent.find(&#39;.qverify__font&#39;).text(&#39;不超过(&#39; + video[0].duration + &#39;)&#39;);
      console.log(&#39;111---&#39; + video[0].duration)
    } else {
      parent.removeClass(&#39;is-error&#39;);
      parent.find(&#39;.qverify__font&#39;).text(&#39;请设置海报帧&#39;);
    }
  })
  /*关闭预览*/
  $(document).undelegate(&#39;.qtuploader__mask&#39;, &#39;click&#39;);
  $(document).delegate(&#39;.qtuploader__mask&#39;, &#39;click&#39;, function() {
    $(this).closest(&#39;.qtuploader__view&#39;).fadeOut(&#39;normal&#39;, function() {
      $(this).closest(&#39;.qtuploader__view&#39;).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;
  }
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more related tutorials, please visit

Html5 Video Tutorial!

Related recommendations:

php public welfare training video tutorial

HTML5 graphic tutorial

HTML5Online Manual

The above is the detailed content of Html5 video upload preview image video, set and preview the poster frame of a certain second of the video. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles