1

我正在尝试使用 QML 创建简单的视频播放器。我安装了 QtSdk 并从源代码编译和安装了 QtMobility。然后我把这个简单的视频播放代码放到主 qml 文件中:

import QtQuick 1.0
import QtMultimediaKit 1.1

Item{
    width: 400; height: 300
    Video {
        id: video
        source: "d:/Projects/Serenity - HD DVD Trailer.mp4"
        anchors.fill: parent
        MouseArea {
            anchors.fill: parent
            onClicked: {
                video.play()
            }
        }
    }
}

编译并运行应用程序后,视频播放断断续续,在退出应用程序时,它会将其放入日志中:

2011-06-07 11:13:44.055 video-player[323:903] *** __NSAutoreleaseNoPool(): Object 0x10225ea60 of class NSCFNumber autoreleased with no pool in place - just leaking
2011-06-07 11:13:45.007 video-player[323:903] *** __NSAutoreleaseNoPool(): Object 0x10264f030 of class __NSCFDate autoreleased with no pool in place - just leaking
2011-06-07 11:13:45.007 video-player[323:903] *** __NSAutoreleaseNoPool(): Object 0x11a409000 of class NSCFTimer autoreleased with no pool in place - just leaking
2011-06-07 11:13:45.008 video-player[323:903] *** __NSAutoreleaseNoPool(): Object 0x11a43e550 of class NSCFArray autoreleased with no pool in place - just leaking
2011-06-07 11:13:45.008 video-player[323:903] *** __NSAutoreleaseNoPool(): Object 0x11a462560 of class __NSFastEnumerationEnumerator autoreleased with no pool in place - just leaking

有什么方法可以让它播放流畅并防止记忆?

4

1 回答 1

1

解决了。我已经为此使用了OpenGL。比 Windows 非 GL 版本更有效。这里有一个代码:

QDeclarativeView mainwindow;
mainwindow.setSource(QUrl::fromLocalFile("./qml/app.qml"));
QGLFormat format = QGLFormat(QGL::DirectRendering); // you can play with other rendering formats like DoubleBuffer or SimpleBuffer
format.setSampleBuffers(false);
QGLWidget *glWidget = new QGLWidget(format);
glWidget->setAutoFillBackground(false);
mainwindow.setViewport(glWidget);

注意:当前 QtMobility 版本 (1.1) 有一个错误,即不允许在 Windows 上以 OpenGL 渲染模式播放视频。所以我使用原生 Qt 渲染来取胜。

于 2011-06-22T08:05:28.770 回答