import win.ui;
/*DSG{{*/
var winform = win.form(text="调用APlayer";right=856;bottom=483;bgcolor=15793151 )
winform.add(
btnFullScreen={cls="plus";left=811;top=458;right=847;bottom=481;background="\res\fullscreen.png";db=1;dr=1;notify=1;repeat="center";z=5};
btnPlay={cls="plus";left=10;top=457;right=42;bottom=480;background="\res\play.png";db=1;dl=1;notify=1;repeat="scale";z=6};
btnStop={cls="plus";left=518;top=458;right=550;bottom=481;background="\res\stop-hover.png";db=1;dr=1;notify=1;repeat="scale";z=7};
plus={cls="plus";left=664;top=458;right=692;bottom=481;background="\res\volume.png";db=1;dr=1;repeat="scale";z=3};
trackbar={cls="plus";left=49;top=460;right=514;bottom=478;background="\res\trackbar-bg.jpg";db=1;dl=1;dr=1;foreground="\res\trackbar.jpg";foreLeft=5;foreRepeat="expand";foreRight=14;notify=1;paddingLeft=2;z=1};
video={cls="custom";left=8;top=5;right=848;bottom=453;bgcolor=0;db=1;dl=1;dr=1;dt=1;z=2};
volume={cls="plus";left=690;top=461;right=800;bottom=479;background="\res\trackbar-bg.jpg";db=1;dr=1;foreground="\res\trackbar.jpg";foreLeft=5;foreRepeat="expand";foreRight=14;notify=1;paddingLeft=2;z=4}
)
/*}}*/
winform.btnStop.skin(
background = {
hover = "/res/stop-hover.png";
active = "/res/stop-active.png";
default = "/res/stop.png";
}
)
winform.btnPlay.skin(
checked = {
background = {
hover = "/res/pause-hover.png";
active = "/res/pause-active.png";
default = "/res/pause.png";
}
}
background = {
hover = "/res/play-hover.png";
active = "/res/play-active.png";
default = "/res/play.png";
}
)
winform.btnFullScreen.skin(
background = {
hover = "/res/fullscreen-hover.png";
active = "/res/fullscreen-active.png";
}
)
import thunder.aPlayer;
var aPlayer = thunder.aPlayer(winform.video)
winform.trackbar.setTrackbarRange(1,100);
winform.trackbar.progressPos = 0;
aPlayer.OnOpenSucceeded = function(){
winform.trackbar.setTrackbarRange(1,aPlayer.getDuration())
}
winform.trackbar.showProgress = function(show){
if( !show ){
if( winform.timerProgressId ){
winform.killtimer(winform.timerProgressId);
winform.timerProgressId = null;
}
return;
}
if( winform.timerProgressId ){
return;//避免重复启动定时器
}
//显示视频播放进度
winform.timerProgressId = winform.addtimer( 2000,
function(hwnd,msg,id,tick){
var pos = aPlayer.getPosition()
if(!pos) {
winform.btnPlay.checked = false;
return 0; //播放结束
}
winform.trackbar.progressPos = pos;
}
)
}
winform.btnPlay.oncommand = function(id,event){
if( winform.btnPlay.checked ){
aPlayer.open("http://f1.flv.kankan.xunlei.com/data/cdn_transfer/demo.hflv")
aPlayer.play()
winform.trackbar.showProgress(true);
}
else {
aPlayer.pause();
}
}
winform.btnStop.oncommand = function( id,event ){
aPlayer.close()
winform.btnPlay.checked = false;
}
// 用户拖动滑块触发下面的函数
winform.trackbar.onMouseClick = function(wParam,lParam){
winform.trackbar.showProgress( false );
aPlayer.setPosition( winform.trackbar.progressPos );
winform.trackbar.showProgress( true );
}
winform.volume.setTrackbarRange(1,100);
winform.volume.progressPos = 100;
winform.volume.onPosChanged = function( pos ){
aPlayer.setVolume(pos);
}
winform.btnFullScreen.oncommand = function(id,event){
winform.video.fullscreen(true);
}
// 关闭窗体时退出播放器
winform.onClose = function(hwnd,message,wParam,lParam){
aPlayer.close();
}
//按回车、空格暂停
winform.isDialogMessage = function(hwnd,msg){
if( msg.wParam == 0xD/*_VK_RETURN*/ || msg.wParam == 0x20/*_VK_SPACE*/ ){
msg.hwnd = winform.btnPlay.hwnd;
return;
}
return win.isDialogMessage(hwnd,msg);
}
//全屏快捷键
winform.video.translateAccelerator = function(msg){
if( msg.wParam == 0xD/*_VK_RETURN*/ || msg.wParam == 0x20/*_VK_SPACE*/ ){
msg.hwnd = winform.btnPlay.hwnd;
}
if( msg.wParam == 0x1B/*_VK_ESC*/ ){
winform.video.fullscreen(false);
}
}
winform.show()
win.loopMessage();