QML VLC视频播放器

基于VLC 和QML 的视频播放器

一,效果

二,代码

import QtQuick 2.0
import VLCQt 1.0
import QtQuick.Controls 2.3

Item {
    id:root
    property string processTime: convertTime(vidwidget.time)+"/"+convertTime(vidwidget.length)
    property int timerC: 5

    VlcVideoPlayer {
        id: vidwidget
        anchors.fill: parent
        autoplay:false
        url:"http://1253212728.vod2.myqcloud.com/98179d03vodcq1253212728/1da016b57447398156649474206/f0.flv"
        aspectRatio:"16:9"
        onStateChanged:{
            if(state===1||state===2){

            }
            else if(state===3){

            }
        }
    }

    function convertTime(milliTime){
        var min =Math.floor((milliTime/1000/60) << 0)
        var second =Math.floor((milliTime/1000) % 60);
        if(min.toString().length<2)
            min="0"+min

        if(second.toString().length<2)
            second="0"+second

        return min+":"+second
    }


    function bottomShow(){
        bottomBar.visible=true
        //bottomBarVisibleTimer.restart()
        //root.timerC=5
    }

    function bottomHide(){
        bottomBar.visible=false
        //bottomBarVisibleTimer.stop()
        //root.timerC=5
    }

//    Timer{
//        id:processTimer
//        interval: 1000
//        repeat: true
//        running: true
//        triggeredOnStart: true
//        onTriggered: {
//            processSlider.increase()
//        }
//    }

    MouseArea{
        anchors.fill: parent
        hoverEnabled: true
        onClicked: {
            if(bottomBar.visible){
                bottomHide()
            }else{
                bottomShow()
            }
        }
    }

    Timer{
        id:bottomBarVisibleTimer
        interval: 1000
        repeat: true
        triggeredOnStart: false

        onTriggered: {
            if(root.timerC<=1){
                bottomHide()
            }
            root.timerC--
        }
    }


    Item{
        id:bottomBar
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        height: 60
        Image{
            anchors.fill: parent
            source: "qrc:/images/video/bottomBar.png"
            Image {
                id: conBtn
                width: 24
                height: 28
                anchors.left: parent.left
                anchors.verticalCenter: parent.verticalCenter
                anchors.leftMargin: 50
                state: "pre"
                source: "qrc:/images/video/pause.png"
                states: [
                    State {
                        name: "tag"
                        PropertyChanges {
                            target: conBtn
                            source: "qrc:/images/video/play.png"
                        }
                    }
                ]
                MouseArea{
                    anchors.fill: parent
                    onClicked: {
                        if(conBtn.state==="pre"){
                            vidwidget.pause()
                            conBtn.state="tag"
                            //processTimer.stop()
                        }
                        else{
                            conBtn.state="pre"
                            vidwidget.play()
                           // processTimer.start()
                        }
                    }
                }
            }

            Text {
                id:timeStr
                anchors.left: conBtn.right
                anchors.verticalCenter: conBtn.verticalCenter
                anchors.leftMargin: 25
                color: "#FFFFFF"
                font.pixelSize: 24
                text: root.processTime
            }
            Slider {
                id:processSlider
                from: 0
                value: 0
                stepSize: 1
                anchors.left: timeStr.right
                anchors.leftMargin: 25
                anchors.right: parent.right
                anchors.rightMargin:50
                anchors.verticalCenter: parent.verticalCenter
                to: vidwidget.length/1000.0
                onMoved: {
                    vidwidget.time  = processSlider.value*1000
                }
            }
        }
    }

}

int libvlc_NothingSpecial=0;
    int libvlc_Opening=1;
    int libvlc_Buffering=2;
    int libvlc_Playing=3;
    int libvlc_Paused=4;
    int libvlc_Stopped=5;
    int libvlc_Ended=6;
    int libvlc_Error=7;

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

土拨鼠不是老鼠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值