QML组件'视频'无法播放Qt资源文件中的视频文件

时间:2015-06-22 21:49:13

标签: c++ qt video qml qt-resource

可在此处找到整个项目:

QML Video Test Project

我已经使用三个按钮创建了一个示例应用程序,一个图像和一个视频播放器。按下按钮时,应播放视频。这就是区分按钮的原因:

  1. 访问与应用程序可执行文件位于同一文件夹中的视频文件。
  2. 访问添加到Qt资源文件的视频文件。
  3. 从没有压缩的外部二进制Qt资源文件访问视频文件。
  4. 只有按钮1.在我的应用程序中工作,这篇文章的原因是我已经不知道为什么按钮2和3.无法播放视频。

    应用程序中包含的图像是与外部二进制Qt资源文件中的视频文件打包在一起的图像。从外部资源文件成功读取此映像。这意味着访问外部资源文件不是问题。

    这是main.qml文件:

    for ( long *p = factors.data() + factors.size(); p != factors.data();  )   
    {
        if ( isPrime( --p ) )
        {                                                             
             std::cout << *p << std::endl;                           
             break;           
        }
    }      
    

    按下按钮1我的应用程序输出:

    import QtQuick 2.4
    import QtQuick.Window 2.2
    import com.qml.externalresourcemanager 1.0
    import QtMultimedia 5.4
    import QtQuick.Controls 1.2
    
    Window {
        visible: true
    
        minimumHeight: 700
        minimumWidth: 400
    
        property string imageSelected: ""
        property string videoSelected: ""
    
        ExternalResourceManager {
            id: externalResourceManager
    
            Component.onCompleted: {
                console.log("External resource registered: " + registerExternalResource("file:/../../VideoTest/binaryExpansionFile.rcc"))
                imageSelected = "externalImage.jpg"
            }
        }
    
        Button {
            id: button0
            width: parent.width
            height: parent.height / 7
            anchors.top: parent.top
            text: "Click me to play as local file"
            onClicked: {
                console.log(installPath + "local.mp4")
                videoSelected = installPath + "local.mp4"
            }
        }
    
        Button {
            id: button1
            width: parent.width
            height: parent.height / 7
            anchors.top: button0.bottom
            text: "Click me to play local resource file"
            onClicked: {
                videoSelected = "local.mp4"
            }
        }
    
        Button {
            id: button2
            width: parent.width
            height: parent.height / 7
            anchors.top: button1.bottom
            text: "Click me to play external resource file"
            onClicked: {
                videoSelected = "external.mp4"
            }
        }
    
        Image {
            id: image
            source: imageSelected
            width: parent.width
            height: parent.height * 2 / 7
            anchors.top: button2.bottom
        }
    
        Video {
            id: video
            source: videoSelected
            height: parent.height * 2 / 7
            width: parent.width
            anchors.top: image.bottom
            fillMode: VideoOutput.PreserveAspectFit
    
            onStatusChanged: {
                var temp
    
                switch (playbackState)
                {
                    case MediaPlayer.NoMedia:
                        temp = "MediaPlayer.NoMedia"
                    break;
    
                    case MediaPlayer.Loading:
                        temp = "MediaPlayer.Loading"
                    break;
    
                    case MediaPlayer.Loaded:
                        temp = "MediaPlayer.Loaded"
                    break;
    
                    case MediaPlayer.Buffering:
                        temp = "MediaPlayer.Buffering"
                    break;
    
                    case MediaPlayer.Stalled:
                        temp = "MediaPlayer.Stalled"
                    break;
    
                    case MediaPlayer.Buffered:
                        temp = "MediaPlayer.Buffered"
                    break;
    
                    case MediaPlayer.EndOfMedia:
                        temp = "MediaPlayer.EndOfMedia"
                    break;
    
                    case MediaPlayer.InvalidMedia:
                        temp = "MediaPlayer.InvalidMedia"
                    break;
    
                    case MediaPlayer.UnknownStatus:
                        temp = "MediaPlayer.UnknownStatus"
                    break;
                }
    
                console.log(temp)
    
                if (status === MediaPlayer.Loaded)
                {
                    video.play()
                }
            }
            onBufferProgressChanged: {
                console.log("Buffering: " + bufferProgress * 100)
            }
            onSourceChanged: {
                console.log("Source: " + source)
            }
            onAvailabilityChanged: {
                console.log("Availability: " + availability)
            }
            onErrorChanged: {
                console.log("Error: " + error)
            }
            onErrorStringChanged: {
                console.log("Error String: " + errorString.toString())
            }
            onHasVideoChanged: {
                console.log("Has video: " + hasVideo)
            }
            onPlaybackStateChanged: {
                var temp
    
                switch (playbackState)
                {
                    case MediaPlayer.PlayingState:
                        temp = "MediaPlayer.PlayingState"
                    break;
    
                    case MediaPlayer.PausedState:
                        temp = "MediaPlayer.PausedState"
                    break;
    
                    case MediaPlayer.StoppedState:
                        temp = "MediaPlayer.StoppedState"
                    break;
                }
    
                console.log(temp)
            }
        }
    }
    

    按下按钮2我的应用程序输出:

    Resource path:  "file:/../../VideoTest/binaryExpansionFile.rcc"
    qml: External resource registered: true
    qml: file:/C:/Users/MisterX/Documents/QtProjects/build-VideoTest-Desktop_Qt_5_4_2_MinGW_32bit-Debug/debug/local.mp4
    qml: Source: file:///C:/Users/MisterX/Documents/QtProjects/build-VideoTest-Desktop_Qt_5_4_2_MinGW_32bit-Debug/debug/local.mp4
    qml: MediaPlayer.UnknownStatus
    qml: Has video: true
    qml: MediaPlayer.UnknownStatus
    qml: MediaPlayer.NoMedia
    qml: MediaPlayer.PlayingState
    

    整个项目可以在这里找到: QML Video Test Project

1 个答案:

答案 0 :(得分:1)

使用使用DirectShow后端的MinGW编译器时,这是一个错误。有关详细信息,请参阅此bug report link