HTML5 plug-in-free multimedia Media-detailed introduction to audio and video
黄舟
Release: 2017-03-11 16:02:16
Original
2932 people have browsed it
Audio and video have become more and more popular now In order to ensure cross-browser compatibility , various websites still choose to use flash
(Source code intercepted from Youku)
Multimedia tags
Use
HTML5 adds two multimedia tags, audio and video. The compatibility is pretty good, but lower versions of IE do not support it Yes It allows us to insert audio and video controls without using any browser plug-ins and it is very simple
(source code taken from Bilibili) The usage of the
If the content in the tag is not supported by the browser, it will be displayed. Of course, when using these two elements, at least add the src attribute , the attribute value is the URL of the resource
But each browser supports different media formats due to copyright issues So you can use the following method
to specify different resource formats Also ensures the compatibility of various browsers
Attributes
In addition to src, the audio and video tags also have some public attributes
Attribute
Description
##autoplay
After setting this attribute, the audio/video resource is ready Play immediately
controls
After setting this property, the browser playback control controls will be displayed
loop
After setting this attribute, the audio/video will loop and start playing again after it ends
preload
After setting this attribute, the audio/video will be played when the page is loaded Load and prepare to play (using autoplay will ignore this attribute)
var audio = new Audio('media/xi-Halcyon.mp3');
var btn = document.getElementById('btn');
var vol = document.getElementById('vol');
var cur = document.getElementById('cur');
var dur = document.getElementById('dur');var state = 'pause';
vol.value = 100;
audio.onloadeddata = function(){
dur.textContent = Math.floor(audio.duration) + 's';
}
setInterval(function(){
cur.textContent = Math.floor(audio.currentTime) + 's';
}, 200);
btn.onclick = function(){
if(state === 'play'){
state = 'pause';
btn.textContent = '播放';
audio.pause();
}else{
state = 'play';
btn.textContent = '暂停';
audio.play();
}
}
vol.oninput = function(){
audio.volume = vol.value/100;
}
Copy after login
The above is the detailed content of HTML5 plug-in-free multimedia Media-detailed introduction to audio and video. For more information, please follow other related articles on the PHP Chinese 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