在Meego上使用QML 播放视频
(Zhouhl -) |
hamishwillee
(Talk | contribs) m (Text replace - "Category:MeeGo" to "Category:MeeGo Harmattan") |
||
| (5 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | [[Category:MeeGo]][[Category:Qt Mobility]][[Category:Qt Quick]] | + | {{ArticleMetaData |
| + | |sourcecode=[[Media:MeegoVideoPlayer.zip]] | ||
| + | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| + | |devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | ||
| + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> | ||
| + | |platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | ||
| + | |devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | ||
| + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | ||
| + | |signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> | ||
| + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | ||
| + | |keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | ||
| + | |id= <!-- Article Id (Knowledge base articles only) --> | ||
| + | |language=Lang-Chinese | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by=<!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate=20110701 | ||
| + | |author=[[User:Zhouhl]] | ||
| + | }} | ||
| + | |||
| + | [[Category:MeeGo Harmattan]][[Category:Qt Mobility]][[Category:Qt Quick]] | ||
== 综述 == | == 综述 == | ||
| − | |||
由于目前的最新的 Qt Creator 暂时还不太完善, 因此在 Meego 上开发和视频相关应用的时候,如果我们使用到了Qt Mobility Multimedia API 中的 QML Video elements, 那么我们就需要注意以下事项: | 由于目前的最新的 Qt Creator 暂时还不太完善, 因此在 Meego 上开发和视频相关应用的时候,如果我们使用到了Qt Mobility Multimedia API 中的 QML Video elements, 那么我们就需要注意以下事项: | ||
| Line 27: | Line 50: | ||
</aegis> | </aegis> | ||
</code> | </code> | ||
| − | |||
添加过aegis文件之后,我们就会发现程序可以播放视频了! | 添加过aegis文件之后,我们就会发现程序可以播放视频了! | ||
| − | + | ||
| + | |||
| + | |||
但是现在还存在一个问题,当我们打开视频之后,如果此时我们从侧面推一下程序,把程序切换到后台,我们会发现程序崩溃并自动退出了。 | 但是现在还存在一个问题,当我们打开视频之后,如果此时我们从侧面推一下程序,把程序切换到后台,我们会发现程序崩溃并自动退出了。 | ||
要解决这个问题,我们需要使用QGLWidget 作为一个 viewport。具体来讲,比如我们在main.cpp中可以这样写: | 要解决这个问题,我们需要使用QGLWidget 作为一个 viewport。具体来讲,比如我们在main.cpp中可以这样写: | ||
| Line 48: | Line 72: | ||
} | } | ||
</code> | </code> | ||
| − | |||
| − | |||
对应的,我们需要在pro文件中加入如下代码: | 对应的,我们需要在pro文件中加入如下代码: | ||
<code javascript> | <code javascript> | ||
| Line 59: | Line 81: | ||
setViewport(new QGLWidget()); | setViewport(new QGLWidget()); | ||
</code> | </code> | ||
| + | |||
| + | |||
好了,到此为止,视频播放的程序在Meego上就一切正常了,Have Fun! | 好了,到此为止,视频播放的程序在Meego上就一切正常了,Have Fun! | ||
| Line 65: | Line 89: | ||
== 下载源码和样例程序== | == 下载源码和样例程序== | ||
| + | |||
[[File:MeegoVideoPlayer.zip]] | [[File:MeegoVideoPlayer.zip]] | ||
==相关链接== | ==相关链接== | ||
*[[Qt_开发|Qt 开发]] | *[[Qt_开发|Qt 开发]] | ||
| − | + | *[[Meego开发]] | |
| − | [[Category:Lang- | + | [[Category:Lang-Chinese]] |
Latest revision as of 13:52, 13 June 2012
文章信息
综述
由于目前的最新的 Qt Creator 暂时还不太完善, 因此在 Meego 上开发和视频相关应用的时候,如果我们使用到了Qt Mobility Multimedia API 中的 QML Video elements, 那么我们就需要注意以下事项:
首先,在开发视频相关项目的时候,由于目前的 Qt Creator 没有生成正确的 .aegis 文件,因此我们需要自己做一个.aegis 文件放到qtc_packaging\debian_harmattan目录里面。
aegis文件的大致格式如下:
<aegis>
<request>
<credential name="GRP::video" />
<credential name="GRP::pulse-access" />
<for path="/full/path/of/your/application" />
</request>
</aegis>
例如在本文所附例子程序中,videoplayer.aegis文件的具体内容如下:
<aegis>
<request>
<credential name="GRP::video" />
<credential name="GRP::pulse-access" />
<for path="/opt/VideoPlayer/bin/VideoPlayer" />
</request>
</aegis>
添加过aegis文件之后,我们就会发现程序可以播放视频了!
但是现在还存在一个问题,当我们打开视频之后,如果此时我们从侧面推一下程序,把程序切换到后台,我们会发现程序崩溃并自动退出了。 要解决这个问题,我们需要使用QGLWidget 作为一个 viewport。具体来讲,比如我们在main.cpp中可以这样写:
#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include <QtDeclarative>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDeclarativeView view;
view.setViewport(new QGLWidget());
view.setSource(QUrl("qrc:/qml/main.qml"));
view.showFullScreen();
return app.exec();
}
对应的,我们需要在pro文件中加入如下代码:
QT += opengl在我们的例子程序中是在QmlApplicationViewer的构造函数中,加入
setViewport(new QGLWidget());
好了,到此为止,视频播放的程序在Meego上就一切正常了,Have Fun!
例子程序请参考附件。

