|
打开/关闭音频
测试
<!-- 注意: 音频操作示例现在只能在IE下测试 -->
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>video</title>
</head>
<body>
<input type="button" value="登录" onclick="testLogin()" />
<input type="checkbox" checked="checked" id="checkboxAudioSendId"/>音频发送
<input type="checkbox" checked="checked" id="checkboxAudioRecvId"/>音频接收
<input type="button" value="打开对讲" onclick="testOpenAudio()" />
<input type="button" value="关闭对讲" onclick="testCloseAudio()" />
<div id="msg"></div>
<div id="id_video" style="width:500px; height:400px"></div>
</body>
</html>
<script type="text/javascript" src="http://127.0.0.1:8081/js/jsw.js"></script>
<script type="text/javascript">
window.onload = function () {
jSW.swInit({
url: "http://127.0.0.1:8081", // bv_nginx.exe服务器地址
calltype: jSW.CallProtoType.OCX, // Audio目前必须使用OCX插件模式
});
}
window.onbeforeunload = function () {
jSW.swDeInit();
}
var session = null;
function testLogin() {
if (session) { delete session; }
session = new jSW.SWSession({
server: '127.0.0.1', // 如果是jSW.CallProtoType.OCX方式,这里需要填写具体的IP
port: 9701,
onopen: function (sess) {
sess.swLogin({
user: 'admin',
password: '123456'
});
}
});
// 注册事件的回调函数
session.swAddCallBack('login', sessionCallback);
session.swAddCallBack('logout', sessionCallback);
}
function testLogout() {
if (session) {
session.swLogout();
}
}
function sessionCallback(sender, event, json) {
var info = '';
if ('login' == event) {
info += '登录';
} else if ('logout' == event) {
info += '退出';
}
if (json.code == jSW.RcCode.RC_CODE_S_OK) {
info += '成功';
} else {
info += '失败, error code: ' + json.code;
}
document.getElementById('msg').innerHTML = info + '<br/><textarea rows="18" cols="100" readonly="readonly"> ' + JSON.stringify(json, null, 4) + '</textarea>';
}
function testOpenAudio() {
if(!checkboxAudioSendId.checked && !checkboxAudioRecvId.checked)
{
return;
}
var m_media = (checkboxAudioSendId.checked ? jSW.MEDIADIR.AUDIOSEND : 0 )
+ (checkboxAudioRecvId.checked ? jSW.MEDIADIR.AUDIORECV : 0);
var chanel = session.swGetPuChanel('PU_4C72', 0);
if (chanel) {
var result = chanel.swOpenEx({
div: 'id_video',
prototype: 'auto', //rtmp > hls
callback: function (options, response) {
alert(response.emms.code);
},
media: m_media
});
if (result != jSW.RcCode.RC_CODE_S_OK) {
alert('打开对讲成功: ' + result);
}
} else {
alert('没有该设备通道');
}
}
function testCloseAudio(){
var chanel = session.swGetPuChanel('PU_4C72', 0);
if(chanel){
chanel.swClose();
}
}
</script>
generated by haroopad
|
|