telephant/qml/MediaPopup.qml

72 lines
1.9 KiB
QML
Raw Normal View History

2020-02-28 04:36:47 +00:00
import QtQuick 2.4
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.1
import QtQuick.Layouts 1.3
2020-02-28 11:14:07 +00:00
import QtMultimedia 5.9
2020-02-28 04:36:47 +00:00
Popup {
property var url
id: popup
modal: true
focus: true
2020-02-28 11:14:07 +00:00
height: mediaItem.height + 16
width: mediaItem.width + 16
2020-02-28 04:36:47 +00:00
anchors.centerIn: mainWindow.overlay
2020-02-28 11:14:07 +00:00
Item {
id: mediaItem
2020-02-28 11:42:37 +00:00
anchors.centerIn: parent
width: image.visible ?
image.width :
video.width
height: image.visible ?
image.height :
video.height
2020-02-28 11:14:07 +00:00
Image {
id: image
width: Math.min(sourceSize.width, mainWindow.width * 0.8)
2020-02-28 11:42:37 +00:00
height: Math.min(sourceSize.height, mainWindow.height * 0.8)
2020-02-28 11:14:07 +00:00
anchors.centerIn: parent
smooth: true
fillMode: Image.PreserveAspectFit
source: visible ? url : ""
visible: !(url.endsWith(".webm") || url.endsWith(".mp4"))
}
Video {
id: video
width: metaData.resolution ? Math.min(metaData.resolution.width, mainWindow.width * 0.8) : 0
height: metaData.resolution ? Math.min(metaData.resolution.height, mainWindow.height * 0.8) : 0
autoLoad: true
autoPlay: false
loops: MediaPlayer.Infinite
anchors.centerIn: parent
fillMode: VideoOutput.PreserveAspectFit
source: visible ? url : ""
visible: url.endsWith(".webm") || url.endsWith(".mp4")
onStatusChanged: {
2020-02-28 11:42:37 +00:00
if (status == MediaPlayer.Loaded)
2020-02-28 11:14:07 +00:00
video.play()
}
/*
MouseArea {
anchors.fill: parent
onClicked: {
if (video.playbackState != MediaPlayer.PausedState) {
video.play()
} else {
video.pause()
}
}
}
*/
}
2020-02-28 04:36:47 +00:00
}
}