动态QLabel + mplayer slave模式播放视频,有声音无画面,解决办法

我用QProcess运行mplayer,用 QLabel的winid 将mplayer嵌入到我的程序窗口中。当我用qt的UI designer添加QLabel时,mplayer可以正常播放,但是当我在程序运行时动态生成QLabel时,QLabel的文字可以正常显示,mplayer只有声音没有画面。偶然在qt的论坛中发现了问题的解决方法:

http://www.qtforum.org/article/25844/using-mplayer-in-qt4-4.html

原文:

Hi All,
I use qprocess to run the mplayer in my application. I use Qlabels window ID to embed the player in my window.
Everything works fine when i create the QLabel in qt designer but when i create the QLabel dynamically during runtime the video is not shown on the label but i can hear the audio of the movie file. :rolleyes: 

code i use to creat the label:

QLabel * labelMovie = new QLabel(this);
labelMovie->resize(391,281);
labelMovie->move(260,160);
labelMovie->setText("Show Movie");
labelMovie->show();

QProcess * mplayer_proc = new QProcess();
QStringList arguments;
arguments<<"-slave"<<"-wid"<<QString::number(labelMovie->winId());
arguments<<"-really-quiet"<<"-vo"<<"x11"<<"-zoom"<<"-fs"<<"-loop"<<"0";
arguments<<"/root/abc.mpg";
mplayer_proc->start("mplayer",arguments);

I can see the label with the text "show Movie" in my screen but not the movie. :( 
do i need to set some more properties for the QLabel ? ?( 

解决方法:

Dear Sathyan
Have you tried to force window creation? 
http://doc.trolltech.com/4.4/qcoreapplic…ml#setAttribute
http://doc.trolltech.com/4.4/qt.html#App…nAttribute-enum

 Quoted

Qt::AA_NativeWindows 3 Ensures that widgets have native windows.

Source code

1
2
3
4
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setAttribute(Qt::AA_NativeWindows, true);

It helped inwin32. Might work in Linux too.

我也只在windows中测试了可以正常播放,linux中有待验证。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值