videoWithFlash.js
6.9 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/**
*
*/
var client; //客户端
var pubResultObj; // 存储底层给我的推流结果
var publishObj;
var videoWithFlash={};
window.videoWithFlash=videoWithFlash;
videoWithFlash.flashInit=function (_client){
client=_client;
};
function teaTimeStamp() {
var _teatimestamp= Date.parse(new Date());
return _teatimestamp;
}
$(function () {
//根据传进来的消息,创建老师NativeVideo窗口,进行播流
client.on(MessageTypes.VIDEO_UPDATE,_videoUpdate);
// //学生视频按钮点击
// $("#stuVideo-video").click(function (e) {
// console.log("teacherVideo-video点击");
// $("#stuVideo-video").html(" ");
// $("#stuVideo-video").removeClass("stuVideo-video");
// $("#stuVideo-video").addClass("stuVideo-videoBg");
//
//
// $("#stuVideo-voice").html("");
// $("#stuVideo-voice").addClass("stuVideo-voice");
// $("#stuVideo-voice").removeClass("stuVideo-voiceBg");
//
//
// //获取推流地址
// achieveStupPushStream();
//
//
// });
//
// //学生音频按钮点击
// $("#stuVideo-voice").click(function (e) {
//
// console.log("stuVideo-voice点击");
// $("#stuVideo-video").html("");
// $("#stuVideo-video").removeClass("stuVideo-videoBg");
// $("#stuVideo-video").addClass("stuVideo-video");
//
// $("#stuVideo-voice").html("");
// $("#stuVideo-voice").removeClass("stuVideo-voice");
// $("#stuVideo-voice").addClass("stuVideo-voiceBg");
// });
//老师视频按钮点击
$("#teacherVideo-video").click(function (e) {
console.log("teacherVideo-video点击");
$("#teacherVideo-video").html(" ");
$("#teacherVideo-video").removeClass("teacherVideo-video");
$("#teacherVideo-video").addClass("teacherVideo-videoBg");
$("#teacherVideo-voice").html("");
$("#teacherVideo-voice").addClass("teacherVideo-voice");
$("#teacherVideo-voice").removeClass("teacherVideo-voiceBg");
$(".teacherVideoBg").css("display","none");
$(".teacherVideo").css("background", "#CCCCCC");
$(".teacherVideo-voice").css("bottom","4px");
//获取推流地址
achieveTeaStream();
});
//老师音频按钮点击
$("#teacherVideo-voice").click(function (e) {
console.log("teacherVideo-voice点击");
$("#teacherVideo-video").html("");
$("#teacherVideo-video").removeClass("teacherVideo-videoBg");
$("#teacherVideo-video").addClass("teacherVideo-video");
$("#teacherVideo-voice").html("");
$("#teacherVideo-voice").removeClass("teacherVideo-voice");
$("#teacherVideo-voice").addClass("teacherVideo-voiceBg");
});
});
//获取推流地址
function achieveTeaStream(){
$(".publish").css("display","block");
$(".play").css("display","none");
var paramInfo={
"type": "flash"
};
var pubResult=client.getVideoPublishPath(paramInfo);
console.log("执行getPublishVideoPath,返回的结果",pubResult);
//code为0,代表成功
if (pubResult.code==0){
if(! window.publishflash) {
flashvideo(
'publish',
'100%',
'100%',
function (error, publishflash) {
if (error) {
return console.error(error);
}
window.publishflash = publishflash;
window.publishflashVideoId = teaTimeStamp();
publishURL(pubResult.publishUrl);
},
function (msg) {
console.log(' [publish] native 2 js', msg);
var _msg=JSON.parse(msg);
console.log("_msg===========>",_msg);
if(_msg.data.result == 0){
debugger;
//将之前底层取的推流结果传递给底层
var _successErrorResult= client.publishVideo(pubResult);
console.log("_successErrorResult======>",_successErrorResult)
if(_successErrorResult.code==0){
console.log("底层广播推流成功");
} else if(_successErrorResult.code==1){
console.log("底层广播推流失败,关闭推流");
}
}else {
console.error('publish error');
}
}
)
}
else {
publishURL(pubResult.publishUrl);
}
}
}
function publishURL(rtmpURL) {
const msg = JSON.stringify({
type: 10,
videoId: publishflashVideoId,
data: {
url: rtmpURL
}
});
console.log(publishflash._js2native(msg));
}
// 监听当前是否有视频流更新
function _videoUpdate(callbackDate){
playCallbackDate=callbackDate;
console.log("videoUpdate==============>",playCallbackDate);
if ((callbackDate.status==1)&&(callbackDate.channelId!=='')){
achievePlayStream(playCallbackDate);
}
}
//获取播流地址
function achievePlayStream(_pubResultObj){
console.log("_pubResultObj==========>",_pubResultObj)
var _paramInfo={
"type": "rtmp",
"channelId": _pubResultObj.channelId,//频道号
"classId": _pubResultObj.classId,//课堂号
"siteId": _pubResultObj.siteId,//站点号
"timestamp":_pubResultObj.timestamp,//时间戳
"userId": _pubResultObj.userId,//userId
};
var streamInfo=client.getVideoPlayPath(_paramInfo);
console.log("result是=============>",streamInfo);
$(".teacherVideoBg").css("display","none");
$(".teacherVideo").css("background", "#CCCCCC");
$(".teacherVideo-voice").css("bottom","4px");
// $(".publish").css("display","none");
if(! window.playflash) {
flashvideo(
'play',
'100%',
'100%',
function createPlayReady(error, playflash) {
if (error) {
return console.error(error);
}
window.playflash = playflash;
window.playflashVideoId = teaTimeStamp();
playURL(streamInfo.playUrl);
},
function (msg) {
console.log(' [play] native 2 js', msg);
}
)
}
else {
playURL(streamInfo.playUrl);
}
}
function playURL(rtmpURL) {
const msg = JSON.stringify({
type: 2,
videoId: playflashVideoId,
data: {
url: rtmpURL
// url:'rtmp://123.56.205.116:1935/live/alexwang'
}
});
console.log(playflash._js2native(msg));
}