华为机顶盒视频播放代码一、将其保存为hwvideo.php页面,页面参数的调用及逻辑处理已省略
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=gbk" /> | |
<title>无标题文档</title> | |
<script> | |
var playUrl = "rtsp://10.27.40.132/3/16/20130513/268564408/268564408.ts"; //vod的播放地址 | |
var mediaStr = '[{mediaUrl:"'+ playUrl +'",'; | |
mediaStr += 'mediaCode: "jsoncode1",'; | |
mediaStr += 'mediaType:2,'; | |
mediaStr += 'audioType:1,'; | |
mediaStr += 'videoType:1,'; | |
mediaStr += 'streamType:1,'; | |
mediaStr += 'drmType:1,'; | |
mediaStr += 'fingerPrint:0,'; | |
mediaStr += 'copyProtection:1,'; | |
mediaStr += 'allowTrickmode:1,'; | |
mediaStr += 'startTime:0,'; | |
mediaStr += 'endTime:20000,'; | |
mediaStr += 'entryID:"jsonentry1"}]'; | |
var mp = new MediaPlayer(); //新建一个mediaplayer对象 | |
var instanceId = mp.getNativePlayerInstanceID(); //读取本地的媒体播放实例的标识 | |
function initMediaPlay() | |
{ | |
var playListFlag = 0; //Media Player 的播放模式。 0:单媒体的播放模式 (默认值),1: 播放列表的播放模式 | |
var videoDisplayMode = 1; //MediaPlayer 对象对应的视频窗口的显示模式. 1: 全屏显示2: 按宽度显示,3: 按高度显示 | |
var height = 206; | |
var width = 320; | |
var left = 165; | |
var top = 17; | |
var muteFlag = 0; //0: 设置为有声 (默认值) 1: 设置为静音 | |
var subtitleFlag = 0; //字幕显示 | |
var videoAlpha = 0; //视频的透明度 | |
var cycleFlag = 0; | |
var randomFlag = 0; | |
var autoDelFlag = 0; | |
var useNativeUIFlag = 1; | |
//初始话mediaplayer对象 | |
mp.initMediaPlayer(instanceId,playListFlag,videoDisplayMode, height,width,left,top,muteFlag,useNativeUIFlag,subtitleFlag,videoAlpha,cycleFlag,randomFlag,autoDelFlag); | |
mp.setSingleMedia(mediaStr); //设置媒体播放器播放媒体内容 | |
mp.setAllowTrickmodeFlag(0); //设置是否允许trick操作。 0:允许 1:不允许 | |
mp.setVideoDisplayMode(0); | |
mp.setVideoDisplayArea(left,top,width,height); | |
mp.setNativeUIFlag(0); //设置播放器本地UI显示功能 0:允许 1:不允许 | |
mp.setAudioTrackUIFlag(1); | |
mp.setMuteUIFlag(1); | |
mp.setAudioVolumeUIFlag(1); | |
mp.refreshVideoDisplay(); | |
} | |
function play()//播放 | |
{ | |
initMediaPlay();//首先初始话mediaplayer对象 | |
mp.playFromStart(); //从头开始播放 | |
//mp.stop(); | |
//mp.releaseMediaPlayer(-1); | |
} | |
play(); //视频播放完毕后跳转 | |
function isEnd(){ | |
var curTime = mp.getCurrentPlayTime(); | |
var allTime = mp.getMediaDuration(); | |
if((allTime == curTime) && (curTime != 0)){ | |
clearInterval(z); | |
mp.releaseMediaPlayer(instanceId); | |
window.location.href = "index.php"; | |
} | |
} | |
var z = setInterval(isEnd,2000); | |
</script> | |
<script type="text/javascript"> | |
var epgdomain=Authentication.CTCGetConfig('EPGDomain'); | |
window.document.onkeypress = function(keyEvent) { | |
keyEvent = keyEvent ? keyEvent : window.event; | |
keyEvent.which = keyEvent.which ? keyEvent.which : keyEvent.keyCode; | |
keycontrol(keyEvent.which); | |
} | |
var pau = 0; | |
function keycontrol(obj){ | |
if( obj == 0x08 ) { | |
clearInterval(z); | |
mp.releaseMediaPlayer(instanceId); | |
window.location.href = "index.html"; | |
} else if (obj == 0x0103) { | |
var volume = mp.getVolume() + 5; | |
volume = volume > 100 ? 100 : volume; | |
volume = volume < 0 ? 0 : volume; | |
mp.setVolume(volume); | |
} else if (obj == 0x0104) { | |
var volume = mp.getVolume() - 5; | |
volume = volume > 100 ? 100 : volume; | |
volume = volume < 0 ? 0 : volume; | |
mp.setVolume(volume); | |
} else if (obj == 0x0107) { | |
if (pau == 0) { | |
mp.pause(); | |
pau = 1; | |
} else { | |
mp.resume(); | |
pau = 0; | |
} | |
} else if (obj == 0x0108) { | |
mp.fastForward(8); | |
} else if (obj == 0x0109) { | |
mp.fastRewind(-8); | |
} else if (obj == 0x010E) { | |
mp.stop(); | |
clearInterval(z); | |
window.location.href = "index.html"; | |
} | |
} | |
</script> | |
</head> | |
<body bgcolor="transparent" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"style="background-color: transparent;"> | |
<div style="color:#fff; font-size:20px;"> </div> | |
</body> | |
</html> 二、通过iframe框架调用代码 <div style="position:absolute;left: 165px; top: 17px; width:320px; height:206px;z-index:99;overflow:hidden;"> <iframename="if_smallscreen"id="if_smallscreen"width="320"height="206"src="hwvideo.php?width=320&height=206&left=165&top=17"frameborder="no"scrolling="no"></iframe></div>三、需要注意的事项 (1)如果有背景图片,请保持视频播放区域的背景图片透明; (2)层必须设定宽高,详见第二点代码;(3)设置视频位置必须用到setVideoDisplayArea方法;(4)<body>必须写为<bodybgcolor="transparent" leftmargin="0" topmargin="0" marginwidth="0"marginheight="0" style="background-color: transparent;position:absolute;z-index:0;">,至少保留background-color:transparent以及bgcolor="transparent";(5)视频跨页播放的问题 页面已经跳转到另一个页面去了,而视频仍在播放,若是用iframe嵌套播放的话,则在视频返回的js里加上代码:var if_smallscreen = document.getElementByIdx_x("if_smallscreen");if_smallscreen.mp.stop(); 其中if_smallscreen为iframe的对象id若并未用iframe嵌套播放,则参见第一点代码。 |