Add basic behavior to play, show catalog and more basic feature

This commit is contained in:
stilobique committed 2026-11-08 12:06:15 +01:00
1 parent df847becc8
commit 8e6392a84c
17 files changed
+1455 -34

No files matched your search

+244
View File
@@ -0,0 +1,244 @@
import QtQuick 2.5
import "../Components"
import "../Shared"
import "../Shared/Remote.js" as Remote
import "../Shared/Format.js" as Format
// Lecteur plein écran.
// Télécommande : OK = lecture/pause, Gauche/Droite = -10 s/+30 s, Haut/Bas = afficher les
// informations, Retour = quitter (géré par le Navigator).
// La progression est signalée au serveur (reprise, « vu ») au démarrage, toutes les 10 s et à l'arrêt.
FocusScope {
id: player
// Injectés par le Navigator
property var navigator: null
property var session: null
property Item initialFocus: null
property bool fullscreen: true
// Paramètres de push("Player", …)
property string itemId: ""
property string title: ""
property real startMs: 0
property var info: null // résultat de Session.preparePlayback()
property bool started: false // lecture effectivement démarrée et signalée
property bool resumed: false
// Reprise atteinte (ou lecture depuis le début) : avant ça, on ne signale rien, pour
// ne pas écraser le point de reprise si le déplacement initial échoue.
property bool resumeReached: startMs <= 0
property bool finished: false
property string error: ""
function showOsd() {
osd.shown = true;
osdTimer.restart();
}
function seekBy(deltaMs) {
if (video.duration <= 0)
return;
video.seek(video.position + deltaMs);
showOsd();
}
// Rien n'est signalé tant que la lecture n'a pas réellement démarré : un arrêt
// signalé à la position 0 effacerait le point de reprise sur le serveur.
function report(event) {
if (!player.info || !player.started)
return;
if (event !== "start" && video.position <= 0)
return;
player.session.reportPlayback(event, player.info, video.position, video.playerState === "paused");
}
// Signale le démarrage une fois la lecture lancée ET la position de reprise atteinte.
function maybeReportStart() {
if (player.started || !player.info || video.playerState !== "playing" || !player.resumeReached)
return;
player.started = true;
player.report("start");
}
function finish() {
if (finished)
return;
finished = true;
report("stop");
player.navigator.pop();
}
Component.onCompleted: {
showOsd();
player.session.preparePlayback(itemId, function (err, playback) {
if (err) {
player.error = err;
return;
}
player.info = playback;
video.source = playback.url;
});
}
// Retour (le Navigator dépile) ou fin : on signale l'arrêt au serveur.
Component.onDestruction: {
if (!finished) {
finished = true;
report("stop");
}
}
Keys.onPressed: {
var key = event.key;
if (Remote.isAccept(key) || key === Qt.Key_Space || key === Qt.Key_MediaTogglePlayPause
|| key === Qt.Key_MediaPlay || key === Qt.Key_MediaPause) {
video.togglePause();
showOsd();
} else if (key === Qt.Key_Left || key === Qt.Key_AudioRewind) {
seekBy(-10000);
} else if (key === Qt.Key_Right || key === Qt.Key_AudioForward) {
seekBy(30000);
} else if (key === Qt.Key_Up || key === Qt.Key_Down) {
showOsd();
} else {
return;
}
event.accepted = true;
}
Rectangle {
anchors.fill: parent
color: "black"
}
VideoSurface {
id: video
anchors.fill: parent
onPlayerStateChanged: {
player.maybeReportStart();
if (playerState === "paused")
player.showOsd();
}
// Reprise : déplacement une fois la durée connue.
onDurationChanged: {
if (!player.resumed && player.startMs > 0 && duration > 0) {
player.resumed = true;
seek(player.startMs);
}
}
onPositionChanged: {
if (!player.resumeReached && position >= player.startMs - 15000) {
player.resumeReached = true;
player.maybeReportStart();
}
}
onEnded: player.finish()
}
Timer {
interval: 10000
repeat: true
running: player.started && !player.finished
onTriggered: player.report("progress")
}
// Messages au centre : chargement / erreur.
Text {
anchors.centerIn: parent
width: parent.width * 0.7
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
visible: text !== ""
text: player.error !== "" ? player.error + "\nAppuyez sur Retour pour quitter."
: video.playerState === "error" ? video.errorString + "\nAppuyez sur Retour pour quitter."
: video.playerState === "loading" || video.playerState === "idle" ? "Chargement…" : ""
color: player.error !== "" || video.playerState === "error" ? Theme.error : Theme.text
font.pixelSize: Theme.fontBody
style: Text.Outline
styleColor: "black"
}
// Informations de lecture (masquées après 4 s, sauf en pause).
Item {
id: osd
property bool shown: true
anchors.fill: parent
opacity: shown || video.playerState === "paused" ? 1 : 0
Behavior on opacity { NumberAnimation { duration: 200 } }
Rectangle {
anchors { left: parent.left; right: parent.right; bottom: parent.bottom }
height: 170
gradient: Gradient {
GradientStop { position: 0; color: "transparent" }
GradientStop { position: 1; color: "#E0000000" }
}
}
Column {
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
margins: Theme.pageMargin
}
spacing: Theme.spacingS
Text {
width: parent.width
text: player.title
elide: Text.ElideRight
color: Theme.text
font.pixelSize: Theme.fontTitle - 6
font.bold: true
}
Rectangle {
width: parent.width
height: 6
radius: 3
color: "#55FFFFFF"
Rectangle {
width: video.duration > 0 ? parent.width * Math.min(1, video.position / video.duration) : 0
height: parent.height
radius: 3
color: Theme.accent
}
}
Item {
width: parent.width
height: stateText.implicitHeight
Text {
id: stateText
text: video.playerState === "paused" ? "Pause"
: video.playerState === "playing" ? "Lecture"
: video.playerState === "loading" ? "Chargement…" : ""
color: Theme.text
font.pixelSize: Theme.fontSmall
font.bold: true
}
Text {
anchors.right: parent.right
text: Format.clock(video.position) + " / " + Format.clock(video.duration)
color: Theme.text
font.pixelSize: Theme.fontSmall
}
}
}
}
Timer {
id: osdTimer
interval: 4000
onTriggered: osd.shown = false
}
}