-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
179 lines (178 loc) · 6 KB
/
index.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<script type="text/javascript" src="nePublisher.min.js"></script>
<link rel="stylesheet" type="text/css" href="buttons.css">
<style type="text/css">
.m-input {
margin-bottom: 10px;
}
.u-input-name {
display: inline-block;
width: 85px;
}
.u-input {
width: 500px;
height: 25px;
border: none;
border-bottom: 1px solid #000;
outline: none;
color: #000;
}
.testBtn {
width: 150px;
}
.u-status {
margin-left: 10px;
display: inline-block;
}
</style>
</head>
<body>
<h1>推流Demo</h1>
<div class="m-input">
<span class="u-input-name">摄像头:</span>
<select class="u-input" id="cameraSelect">
</select>
</div>
<div class="m-input">
<span class="u-input-name">麦克风:</span>
<select class="u-input" id="microPhoneSelect">
</select>
</div>
<div class="m-input">
<span class="u-input-name">清晰度:</span>
<select class="u-input" id="qualitySelect">
<option value="0">流畅(480*360@20)</option>
<option value="1">标清(640*480@20)</option>
<option value="2">高清(960*540@20)</option>
</select>
</div>
<div class="m-input">
<span class="u-input-name">推流地址:</span>
<input class="u-input" type="text" id="publishUrl">
</div>
<div class="m-input">
<button class="button button-primary button-rounded testBtn" id="previewBtn" onclick="startPreview()">预览</button>
<button class="button button-primary button-rounded testBtn" id="publishBtn" onclick="startPublish()">开始直播</button>
<span class="u-status"></span>
</div>
<object width="862" height="486" id="my-publisher" type="application/x-shockwave-flash" data="publisher-ebd4e1deba.swf" style="visibility: visible;"><param name="wmode" value="transparent"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="quality" value="high"><param name="align" value="middle"><param name="flashvars" value="id=100&width=862&height=486&js_bridge_method=nePublisher.js_bridge_message"></object>
<script type="text/javascript">
var cameraList,
microPhoneList,
cameraOptions = '',
microPhoneOptions = '';
var publishBtn = document.getElementById('publishBtn');
var previewBtn = document.getElementById('previewBtn')
var testInput = document.getElementsByClassName('u-input');
var myPublisher = new nePublisher('my-publisher', {
//viewOptions
videoWidth: 960,
videoHeight: 540,
fps: 20,
bitrate: 1500
}, {
//flashOptions
previewWindowWidth: 862,
previewWindowHeight: 486,
wmode: 'transparent',
quality: 'high',
allowScriptAccess: 'always'
}, function() {
cameraList = this.getCameraList();
microPhoneList = this.getMicroPhoneList();
for (var i = cameraList.length - 1; i >= 0; i--) {
cameraOptions = '<option value="' + i + '">' + cameraList[i] + '</option>' + cameraOptions;
}
for (var i = microPhoneList.length - 1; i >= 0; i--) {
microPhoneOptions = '<option value="' + i + '">' + microPhoneList[i] + '</option>' + microPhoneOptions;
}
document.getElementById("cameraSelect").innerHTML = cameraOptions;
document.getElementById("microPhoneSelect").innerHTML = microPhoneOptions;
}, function(code, desc) {
console.log(code, desc);
});
var qualityList = [
{
//流畅
fps: 20,
bitrate: 600,
videoWidth:480,
videoHeight:360
},
{
//标清
fps: 20,
bitrate: 800,
videoWidth:640,
videoHeight:480
},
{
//高清
fps: 20,
bitrate: 1500,
videoWidth:960,
videoHeight:540
}
];
var getCameraIndex = function() {
var cameraSelect = document.getElementById("cameraSelect");
var cameraIndex = cameraSelect.selectedIndex;
return cameraSelect.options[cameraIndex].value;
};
var getMicroPhoneIndex = function() {
var microPhoneSelect = document.getElementById("microPhoneSelect");
var microPhoneIndex = microPhoneSelect.selectedIndex;
return microPhoneSelect.options[microPhoneIndex].value;
};
var getQualityOption = function() {
var qualitySelect = document.getElementById("qualitySelect");
var qualityIndex = qualitySelect.selectedIndex;
return qualityList[qualityIndex];
};
var startPreview = function() {
myPublisher.startPreview(getCameraIndex());
document.getElementsByClassName('u-status')[0].innerHTML = '预览中';
};
var startPublish = function() {
var publishUrl = document.getElementById("publishUrl").value;
startPublishCall();
myPublisher.setCamera(getCameraIndex());
myPublisher.setMicroPhone(getMicroPhoneIndex());
myPublisher.startPublish(publishUrl, getQualityOption(),function(code, desc) {
console.log(code, desc);
alert(code + ':' + desc);
stopPublishCall();
});
};
var stopPublish = function() {
myPublisher.stopPublish();
stopPublishCall();
};
var startPublishCall = function() {
console.log('推流开始');
document.getElementsByClassName('u-status')[0].innerHTML = '直播中';
publishBtn.innerHTML = '停止直播';
publishBtn.onclick = stopPublish;
for (var i = testInput.length - 1; i >= 0; i--) {
testInput[i].disabled = true;
}
previewBtn.disabled = true;
};
var stopPublishCall = function() {
console.log('推流结束');
document.getElementsByClassName('u-status')[0].innerHTML = '预览中';
publishBtn.innerHTML = '开始直播';
publishBtn.onclick = startPublish;
for (var i = testInput.length - 1; i >= 0; i--) {
testInput[i].disabled = false;
}
previewBtn.disabled = false;
};
</script>
</body>
</html>