首页 > 其他 > 详细

使用MPlayer开发万能播放器-原理篇

时间:2014-02-23 08:26:57      阅读:400      评论:0      收藏:0      [点我收藏+]

        先秀一秀效果图:

    bubuko.com,布布扣

1、MPlayer简介
      MPlayer是一款开源多媒体播放器,以GNU通用公共许可证发布。此款软件可在各主流作业系统使用,例如Linux和其他类Unix系统、Windows及Mac OS X系统。
       MPlayer建基于命令行界面,在各作业系统也可选择安装不同的图形界面。mplayer的另一个大的特色是广泛的输出设备支持。它可以在X11、Xv、DGA、OpenGL、SVGAlib、fbdev、AAlib、DirectFB下工作,且能使用GGI和SDL和一些低级的硬件相关的驱动模式(比如Matrox、3Dfx和Radeon、Mach64、Permedia3)。MPlayer还支持通过硬件MPEG解码卡显示,如DVB 和DXR3与Hollywood+。
       MPlayer的开发始于2000年。最初的作者是 Arpad Gereoffy。MPlayer最初的名字叫"MPlayer - The Movie Player for Linux",不过后来开发者们简称其为"MPlayer - The Movie Player",原因是MPlayer已经不仅可以用于Linux而可以在所有平台上运行。

    MPlayer下载地址:http://Jempson.7958.com/down_10948103.html

2、实现原理
   
为MPlayer编写GUI程序有两种方法:
       a、MPlayer源码
             这种方法需要读懂MPlayer的源码,
直接修改他里面的代码,这样我们做得界面就能够和MPlayer一体了(当然也能够通过link mplayer用到的任何的库和.o文档,把他无缝的集成在程式里面)      
       b、使用Slave模式
            
所谓的slave模式,就是mplayer在运行过程中能够接收用户的输入命令行,具体支持哪些命令行,能够通过mplayer -input cmdlist这条命令来得到,在Mplayer源码的slave.txt中也有对这些命令有详细的讲解。Slave模式下工作的Mplayer可以和系统的标准输入、输出进行信息交互。我们可以用linux C编程来完成对slave模式工作的Mplayer进行控制和信息获取。
            由于使用AAuto开发,所以使用方案B。

3、Slave模式命令
       Slave模式命令繁多,主要的有以下几个(来自文档:http://dd.ma/ffQiTkCK):

          MPlayer暂停:

 pause                                 Pause/unpause the playback.

  MPlayer标准时间输出:

  get_time_pos                   Print out the current position in the file in seconds, as float.

  get_time_length               Print out the length of the current file in seconds.

  等等:了解全面命令,下载文档:http://dd.ma/ffQiTkCK

4、AAuto代码
           了解以上的原理,开发还是比较简单的。主要使用process.popen,进行管道之间的数据交换。第一版本的代码如下:

           

import win.ui;
import fsys.dlg;
import win.ui.menu;
import process.popen;

/*DSG{{*/
var winform = ..win.form(text="播放器";right=654;bottom=422;border="none")
winform.add(
video={cls="static";top=20;right=656;bottom=424;ah=1;aw=1;bgcolor=0;db=1;dl=1;dr=1;dt=1;left=0;z=1};
)
/*}}*/

import web.layout;
import web.layout.behavior.windowSizer;//支持拖动边框
import web.layout.behavior.windowCommand;//支持标题栏按钮

wbLayout = web.layout( winform )  
wbLayout.go("/layout/frmRound.html") 

//圆角窗口
import win.util.round;
win.util.round(winform);

// 创建player
..player = null;
var openVideo = function(filepath){
	
	if(..player != null){
		..player.process.kill();
    	..player.close();
	}
	
	..player = process.popen(io.fullpath("/mplayer/mplayer.exe"), "-vo gl -identify -slave -noquiet -wid " + winform.video.hwnd + " " + filepath);
	
}


winform.onClose = function(hwnd,message,wParam,lParam){
    if(..player != null){
    	..player.process.kill();
    	..player.close();
    }
}

winform.popmenu = win.ui.popmenu(winform);//创建弹出菜单 
winform.popmenu.add(
	‘打开‘,
	function(id){ 
		var filepath = fsys.dlg.open("所有文件|*.*||","选择文件");
		if(filepath!=null){
			openVideo(filepath);
		}
	}
);
winform.popmenu.add(‘退出‘,function(id){ winform.close() })

winform.wndproc = function(hwnd,message,wParam,lParam){
	select(message) {
		case 0x204/*_WM_RBUTTONDOWN*/{   
			winform.popmenu.popup( win.getMessagePos(lParam) );//弹出菜单
		} 
	} 
} 

winform.show() 
win.loopMessage();
return winform;

         源码下载地址:http://dd.ma/Bf1PEARM

使用MPlayer开发万能播放器-原理篇

原文:http://blog.csdn.net/zhangjp/article/details/19693713

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!