Home Web Front-end H5 Tutorial Detailed explanation of HTML5 video tag testing application

Detailed explanation of HTML5 video tag testing application

May 19, 2017 pm 04:50 PM

1. Use of video tag

Attributes: src (path to the audio file to be played), autoplay (whether to play automatically), control (progress bar), loop (loop playback) ), onended (whether the completion of playback is an event)

2. Implemented a simple player

The interface is as follows:


3. Function

is mainly accomplished through onclick and onended events. Specifically, all the above are implemented, but there are requirements for the naming of audio files. Please see Code

4. Code:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

<!DOCTYPE HTML>

<html>

<head>

<title>播放视频</title>

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>

</head>

<body>

<p style="cursor:pointer;" onclick="javascript:playvideo(1);">播放视频</p>

<p style="cursor:pointer;" onclick="javascript:playvideo(2);">关闭视频</p>

<video id="video" style="width:1024px; height:600px; margin:0 auto; display:none;" src="./mybroadcast2.mkv" autoplay="autoplay" controls="controls" onended="javascript:videoover();" onclick="javascript:screen_stop();" ondblclick="javascript:double_click();">您的浏览器暂不支持播放该视频,请升级至最新版浏览器。</video>

<button id="hary_run" style="width:100px; height:35px; cursor:pointer;" onclick="javascript:controlTV('hary_run');">快进</button>

<button id="stop_run" style="width:100px; height:35px; cursor:pointer;" onclick="javascript:controlTV('stop_run');">暂停</button>

<button id="current_run" style="width:100px; height:35px; cursor:pointer;" disabled=true onclick="javascript:controlTV('current_run');">播放</button>

<button id="open_voice" style="width:100px; height:35px; cursor:pointer;" onclick="javascript:controlTV('open_voice');">静音</button>

<button id="close_voice" style="width:100px; height:35px; cursor:pointer;" disabled=true onclick="javascript:controlTV('close_voice');">取消静音</button>

</body>

<script>

function playvideo(type){

var openvideo = document.getElementById("video");

if (type == 1){

openvideo.style.display = "block";

} else if (type == 2){

openvideo.style.display = "none";

}

}

// 让视频循环列表播放

function videoover(){

var videoId = document.getElementById("video");

var video_path = videoId.src;

var path_begin = video_path.substring(0, video_path.lastIndexOf(".")-1);

var path_end = video_path.substring(video_path.lastIndexOf("."));

var num = parseInt(video_path.charAt(video_path.lastIndexOf(".")-1));

if (num >= 3) {

num = 0;

} else {

num++;

}

videoId.src = path_begin + num.toString() + path_end;

}

// 控制视频

function controlTV(oprationId){

var runId = document.getElementById(oprationId);

var btn_value = runId.innerText;

// 获取媒体播放Id

var videoId = document.getElementById("video");

if ("快进" == btn_value){

// 获取当前播放进度

var current_pro = videoId.currentTime;

videoId.currentTime = current_pro + 10;

} else if ("暂停" == btn_value) {

videoId.pause();

runId.disabled = true;

var broad_btn = document.getElementById("current_run");

broad_btn.disabled = false;

} else if ("播放" == btn_value) {

videoId.play();

runId.disabled = true;

var stop_btn = document.getElementById("stop_run");

stop_btn.disabled = false;

} else if ("静音" == btn_value) {

videoId.muted = true;

runId.disabled = true;

btn_disabled = document.getElementById("close_voice");

btn_disabled.disabled = false;

} else if ("取消静音" == btn_value) {

videoId.muted = false;

runId.disabled = true;

var btn_disabled = document.getElementById("open_voice");

btn_disabled.disabled = false;

}

}

function screen_stop(){

// 获取媒体播放Id

var videoId = document.getElementById("video");

// 判断是否已暂停

if (videoId.paused) {

videoId.play();

} else {

videoId.pause();

}

}

/*----------------------------------兼容性解决方案---------------------------------------------*/

// 进入全屏

function requestFullScrren(){

var de = document.documentElement;

if (de.requestFullscreen) {

// W3C 提议

de.requestFullscreen();

} else if (de.mozRequestFullScreen) {

// Firefox 10+

de.moRequestFullScreen();

} else if (de.webkitRequestFullScreen) {

// Webkit (works in Safari5.1 and Chrome 15)

de.webkitRequestFullScreen();

}

}

// 退出全屏

function exitFullScreen(){

var de = document;

if (de.exitFullscreen) {

// W3C 提议

de.exitFullscreen();

} else if (de.mozCancelFullScreen) {

// Firefox 10+

de.mozCancelFullScreen();

} else if (de.webkitCancelFullScreen) {

// Webkit (works in Safari5.1 and Chrome 15)

de.webkitCancelFullScreen();

}

}

// 双击全屏

function double_click(){

if (requestFullScrren) {

requestFullScrren();

} else {

exitFullScreen();

}

}

// 自动加载默认配置(未完成)

/**function onload_property(){

// 获取媒体播放Id

var videoId = document.getElementById("video");

var file = new ActiveXObject("Scripting.FileSystemObject");

var inputStream = file.OpenTextFile("customvideo.properties");

var content = "";

while(!inputStream.atEndOfLine){

content + inputStream.readLine + "\n";

}

inputStream.close();

}

window.onload = onload_property;**/

</script>

</html>

Copy after login

[Related recommendations]

1. Solution to the problem that the H5 video tag can only play sound but not video

2. The MIME of IIS does not register the MP4 type, resulting in the solution that the vidoe tag cannot be recognized

3. Share an example of making a banner using HTML5

4. Overview of the power and future development of HTML5

5. Introduction to the use of the latest h5 tag datalis

The above is the detailed content of Detailed explanation of HTML5 video tag testing application. 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 Article Tags

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)

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

Nested Table in HTML

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

Table Border in HTML

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

HTML margin-left

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

HTML Table Layout

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

Moving Text in HTML

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

HTML Ordered List

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

HTML onclick Button

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

HTML Input Placeholder

See all articles