基于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;