Skip to content

Instantly share code, notes, and snippets.

@Axel-Erfurt
Created January 8, 2021 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Axel-Erfurt/d2af483c3001876199a144f2d99076d6 to your computer and use it in GitHub Desktop.
Save Axel-Erfurt/d2af483c3001876199a144f2d99076d6 to your computer and use it in GitHub Desktop.
QML VideoPlayer
import QtQuick 2.2
import QtQuick.Window 2.2
import QtMultimedia 5.0
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.0
ApplicationWindow {
id: window
flags: Qt.Window | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
visible: true
color: "#000000"
minimumHeight: 160
minimumWidth: 285
width: 480
height: 270
x: 100
y: 100
FileDialog {
id: dlg
nameFilters: [ "Video files (*.mp4 *.flv *.ts *.mpg *.3gp *.ogv *.m4v *.mov)", "All files (*)" ]
title: "Please choose a video file"
folder: shortcuts.movies
selectMultiple: false
sidebarVisible: true
modality: Qt.WindowModal
onAccepted: {
console.log("You chose: " + dlg.fileUrls)
player.source = dlg.fileUrl
autoplay: true
return
}
onRejected: {
console.log("Canceled")
return
}
}
DropArea {
id: drop
anchors.fill: parent
enabled: true
onEntered:
console.log("entered");
onExited:
console.log("exited")
onDropped: {
drop.acceptProposedAction()
if (drop.hasUrls)
{
console.log("dropped url:", drop.urls)
player.source = drop.urls[0]
}
else if (drop.hasText)
{
console.log("dropped text:", drop.text)
player.source = drop.text
}
}
}
Item {
id: myurls
focus: true
Keys.onPressed: {
if (event.key === Qt.Key_Q) Qt.quit()
if (event.key === Qt.Key_F)
if (window.visibility === Window.FullScreen) window.showNormal()
else if (window.visibility === Window.Windowed) window.showFullScreen()
if (event.key === Qt.Key_Down)
if (player.volume > 0.1) player.volume -= 0.1
if (event.key === Qt.Key_Up)
if (player.volume < 1.0) player.volume += 0.1
if (event.key === Qt.Key_M)
if (player.muted === true) player.muted = false
else if (player.muted === false) player.muted = true
if (event.key === Qt.Key_U) console.log(myclip)
if (event.key === Qt.Key_Right) player.seek(player.position + 20000)
if (event.key === Qt.Key_Left) player.seek(player.position - 20000)
if (event.key === Qt.Key_Space)
if (player.playbackState == MediaPlayer.PlayingState)
player.pause()
else
player.play()
}
Menu {
id: contextMenu
MenuItem {
text: 'open File'
iconName: "document-open"
onTriggered: dlg.visible = true
shortcut: "o"
}
MenuSeparator {
}
MenuItem {
text: 'Exit'
iconName: "window-close"
onTriggered: Qt.quit()
shortcut: "q"
}
}
}
Rectangle {
Component.onCompleted:
{
console.log("Welcome ...")
}
width: parent.width
height: parent.height
anchors.bottom: parent.bottom
color: "black"
Video {
id: player
autoPlay: true
anchors.fill: parent
volume: 0.9
}
}
MouseArea{
id: iMouseArea
acceptedButtons: Qt.LeftButton | Qt.RightButton
property int prevX: 0
property int prevY: 0
anchors.fill: parent
onWheel: {
if (wheel.angleDelta.y > 0)
{window.width += 20;
window.height = window.width / 1.778;}
else
{window.width -= 20;
window.height = window.width / 1.778;}
}
onPressed: {prevX=mouse.x; prevY=mouse.y}
onPositionChanged:{
var deltaX = mouse.x - prevX;
window.x += deltaX;
prevX = mouse.x - deltaX;
var deltaY = mouse.y - prevY
window.y += deltaY;
prevY = mouse.y - deltaY;
}
onClicked: {
if (mouse.button === Qt.RightButton)
contextMenu.popup()
else if (mouse.button === Qt.LeftButton)
return
}
}
}
@Axel-Erfurt
Copy link
Author

start with

qmlscene QuickPlayer.qml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment