import fonts.fontAwesome;
import win.ui;
/*DSG{{*/
var winform = win.form(text="万能播放器 - 调用libvlc";right=856;bottom=483;bgcolor=16515070;clipch=1;parent=...)
winform.add(
btnFullScreen={cls="plus";text='\uF047';left=811;top=453;right=852;bottom=483;color=1938422;db=1;dr=1;font=LOGFONT(h=-16;name='FontAwesome');iconStyle={align="left";font=LOGFONT(h=-13;name='FontAwesome');padding={left=8}};notify=1;repeat="center";z=4};
btnPlay={cls="plus";text='\uF04B';left=10;top=456;right=42;bottom=479;color=1938422;db=1;dl=1;font=LOGFONT(h=-19;name='FontAwesome');notify=1;repeat="scale";z=5};
btnStop={cls="plus";left=518;top=458;right=550;bottom=481;background="I:\系统下载目录\aplayer视频播放器\res\stop-hover.png";db=1;dr=1;notify=1;repeat="scale";z=6};
plus={cls="plus";text='\uF027';left=666;top=457;right=691;bottom=480;color=1938422;db=1;dr=1;font=LOGFONT(h=-19;name='FontAwesome');repeat="scale";z=2};
trackbar={cls="plus";left=49;top=460;right=652;bottom=472;bgcolor=-2512093;border={radius=-1};color=23807;db=1;dl=1;dr=1;foreRepeat="expand";foreRight=13;forecolor=-14911489;notify=1;paddingBottom=5;paddingTop=5;z=1};
video={cls="custom";left=8;top=6;right=848;bottom=447;bgcolor=0;db=1;dl=1;dr=1;dt=1;z=7};
volume={cls="plus";left=696;top=461;right=812;bottom=473;bgcolor=-2512093;border={radius=-1};color=23807;db=1;dr=1;foreRepeat="expand";foreRight=13;forecolor=-14911489;notify=1;paddingBottom=5;paddingTop=5;z=3}
)
/*}}*/

import libvlc; 
import win.version;

//初始化vlc引擎，可用参数：https://wiki.videolan.org/VLC_command-line_help/ 
var vlcEngine = libvlc(
	"--subsdec-encoding=GB18030",//字幕默认使用中文编码
	win.version.isVistaLater ? "--freetype-font=DFKai-SB" : "--freetype-font=宋体",//WIN7可用字体：Arial Unicode MS,DFKai-SB, Microsoft JhengHei, MingLiU, MingLiU-ExtB, MingLiU_HKSCS, MingLiU_HKSCS-ExtB, PMingLiU, PMingLiU-ExtB
	"-I","dummy","--ignore-config"//,"--extraintf=logger" ,"--verbose=2" 
	)
	
//创建播放器
var vlcPlayer = vlcEngine.mediaPlayer( winform.video );
vlcPlayer.setKeyInput(true)

var eventManager = vlcPlayer.getEventManager()
eventManager.mediaPlayerTimeChanged = function(event){ 
	if( !winform.trackbar.state.active ){
		
		winform.trackbar.progressPos = event.newTime
	} 	
}

eventManager.mediaPlayerLengthChanged = function(event){ 
    winform.btnPlay.disabledText = null;
	winform.trackbar.setTrackbarRange(1,vlcPlayer.length);
	winform.trackbar.progressPos = 0;
	//vlcPlayer.spuLoad("字幕路径");
}  

import fsys.dlg;
winform.btnPlay.oncommand = function(id,event){  
    
 	if( winform.btnPlay.checked ){ 
 		if(!vlcPlayer.isStopped() && !vlcPlayer.isPaused() &&  !vlcPlayer.isEnded() ){
 			//vlcPlayer.loadMediaFile(fsys.dlg.open(,"请指定视频文件")); 
 			vlcPlayer.loadMedia("http://download.aardio.com/demo/video.aardio"); 
 			winform.btnPlay.disabledText = {'\uF254';'\uF251';'\uF252';'\uF253';'\uF250'}
 		}
 	
		vlcPlayer.play()   
	}
	else {
		vlcPlayer.pause(); 
	} 
	
} 

winform.btnStop.oncommand = function( id,event ){
	vlcPlayer.stop()
	winform.btnPlay.checked = false; 
}
  
winform.volume.setTrackbarRange(1,100);
winform.trackbar.onMouseUp = function(){
    vlcPlayer.pause()
	vlcPlayer.time = winform.trackbar.progressPos; 
	vlcPlayer.play()
} 

winform.volume.setTrackbarRange(1,100);
winform.volume.progressPos = 100;
winform.volume.onMouseUp = function(){ 
	vlcPlayer.volume = pos;
} 

winform.btnFullScreen.oncommand = function(id,event){
	winform.video.fullscreen(true);
} 

// 关闭窗体时退出播放器
winform.onClose = function(hwnd,message,wParam,lParam){
    vlcPlayer.release()
}

//按回车、空格暂停
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.adjust = function( cx,cy,wParam ) {	 
	for(name,ctrl in winform.eachControl("plus") ){
		ctrl.redrawTransparent(); //修正内部裁剪不重绘
	} 
};

winform.volume.skin({
	background={
		default=0xFF23ABD9
	};
	foreground={
		default=0xFFFF771C;
		hover=0xFFFF6600
	};
	color={
		default=0xFFFF5C00;
		hover=0xFFFF6600
	}
})

winform.trackbar.setTrackbarRange(1,100);
winform.trackbar.skin({
	background={
		default=0xFF23ABD9
	};
	foreground={
		default=0xFFFF771C;
		hover=0xFFFF6600
	};
	color={
		default=0xFFFF5C00;
		hover=0xFFFF6600
	}
})

winform.btnFullScreen.skin({
	color={
		active=0xFF00FF00;
		default=0xFFF6931D;
		disabled=0xFF6D6D6D;
		hover=0xFFFF0000
	}
})

winform.btnPlay.skin({
	color={
		active=0xFF00FF00;
		default=0xFFF6931D;
		disabled=0xFF6D6D6D;
		hover=0xFFFF0000
	}
	checked={
		text = '\uF04D'
	}
})

winform.show() 
win.loopMessage(); 