Html5 video playback and dynamic screenshot implementation steps and code (Other untested safari supported)

Source: Internet
Author: User

Comments: Html5 video playback is dynamic. It is a fashionable and cool function. chrom is not supported for the time being, and safari is not tested. If you need to know about it, you can refer to it and do not support chrom for the time being. Support for safari. Other not tested
REFERENCE The jquery address first. Select Sina's

The Code is as follows:
<Script type = "text/javascript" src = "http://lib.sinaapp.com/js/jquery/1.6/jquery.js"> </script>

Add a video tag

The Code is as follows:
<Video id = "video" controls = "controls">
<Source src = "1.mp4"/>
</Video>

Then js

The Code is as follows:
<Script type = "text/javascript">
$ (). Ready (function (){
Var video, output;
Var scaling = 0.25;
Var initialize = function (){
Output = $ ("# output ");
Video = $ ("# video"). get (0 );
$ ("# Capture"). click (captureImage );
};
Var captureImage = function (){
Var canvas = document. createElement ("canvas ");
Canvas. width = video. videoWidth * scale;
Canvas. height = video. videoHeight * scale;
Canvas. getContext ('2d ')
. DrawImage (video, 0, 0, canvas. width, canvas. height );
Var img = document. createElement ("img ");
Img. src = canvas. toDataURL ();
Output. prepend (img );
};
$ (Initialize );
});
</Script>

It will not be pasted.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.