您的位置:首页 > 其它

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

2013-05-14 10:20 746 查看
我用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.


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中有待验证。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: