Qml播放视频

Qml播放视频比音乐稍微复杂一些,需要使用VideoOutput和MediaPlayer配合。VideoOutput用来渲染视频。

代码如下:

import QtQuick 2.0
import QtMultimedia 5.14

Text {
    text: "Click Me!";
    font.pointSize: 24;
    width: 150; height: 50;
    
    MediaPlayer {
        id: player
        source: "video.mp4"
    }
    //渲染视频
    VideoOutput{
        anchors.fill: parent
        source: player
    }
    
    MouseArea {
        id: playArea
        anchors.fill: parent
        onPressed:  { 
            player.play() 
        }
    }
}

注意:

Windows系统安装LAV FIlters(ffmpeg的DirectShow分离器和音视频解码器),才可以进行播放。

你可能感兴趣的:(C/C++)