Last active
December 19, 2019 02:29
-
-
Save hzlzh/0fbd5642f1a6a61aea22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width,minimum-scale=1.0"/> | |
<title></title> | |
</head> | |
<body> | |
<style type="text/css"> | |
video { | |
max-width: 100%; | |
} | |
</style> | |
<script type="text/javascript"> | |
var html = '' + | |
'<video controls width="600" height="320">' + | |
'<source src="{video}" type=\'{type}\' />' + | |
'<div>对不起你的浏览器不支持播放此视频</div>' + | |
'</video>'; | |
var m = location.search.match(/[a-zA-Z0-9]+=[^&]+/g); | |
var split; | |
for (var i = 0,l = m.length; i < l; i++) { | |
split = m[i].split('='); | |
html = html.replace('{' + split[0] + '}', decodeURIComponent(split[1])); | |
} | |
document.write(html); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
(function() { | |
var data = { | |
htmlUrl: './play.html', | |
videoUrl: './video.mp4', | |
type: 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"' | |
}; | |
var img = document.getElementById('canvas'); | |
var parent = img.parentNode; | |
var video = document.createElement('video'); | |
if (video.canPlayType(data.type)) { | |
// create video | |
var source = document.createElement('source'); | |
source.src = data.videoUrl; | |
source.type = data.type; | |
video.appendChild(source); | |
// create time span | |
var span = document.createElement('span'); | |
span.innerHTML = '00:30'; | |
// create link image | |
var a = document.createElement('a'); | |
a.href = data.htmlUrl + '?video=' + encodeURIComponent(data.videoUrl) + '&type=' + encodeURIComponent(data.type); | |
a.target = '_blank'; | |
parent.removeChild(img); | |
a.appendChild(img); | |
parent.appendChild(video); | |
parent.appendChild(a); | |
parent.appendChild(span); | |
} | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment