1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2025-09-01 08:52:45 +00:00

Move playback logic to C++ side

This commit is contained in:
Chris Josten 2021-02-14 00:21:49 +01:00
parent 5ddd5e8e2e
commit a244c27b1a
8 changed files with 147 additions and 84 deletions

View file

@ -26,7 +26,7 @@ Column {
property real playProgress: 0.0
property bool favourited: false
property alias imageBlurhash: playImage.blurhash
signal playPressed(bool startFromBeginning)
signal playPressed(bool resume)
spacing: Theme.paddingLarge
BackgroundItem {
@ -57,7 +57,7 @@ Column {
color: Theme.highlightColor
width: parent.width * playProgress
}
onClicked: playPressed(false)
onClicked: playPressed(true)
}
Row {
anchors {
@ -71,7 +71,7 @@ Column {
id: playFromBeginning
icon.source: "image://theme/icon-m-backup"
visible: playProgress > 0
onClicked: playPressed(true)
onClicked: playPressed(false)
}
IconButton {
id: favouriteButton

View file

@ -31,15 +31,15 @@ import "../"
SilicaItem {
id: playerRoot
property string itemId
property string title
property alias item : mediaSource.item
property string title: item.name
property alias resume: mediaSource.resumePlayback
property int progress
readonly property bool landscape: videoOutput.contentRect.width > videoOutput.contentRect.height
property MediaPlayer player
readonly property bool hudVisible: !hud.hidden || player.error !== MediaPlayer.NoError
property alias audioTrack: mediaSource.audioIndex
property alias subtitleTrack: mediaSource.subtitleIndex
property real startTicks: 0
// Blackground to prevent the ambience from leaking through
Rectangle {
@ -50,22 +50,10 @@ SilicaItem {
PlaybackManager {
id: mediaSource
apiClient: ApiClient
itemId: playerRoot.itemId
mediaPlayer: player
autoOpen: true
onStreamUrlChanged: {
if (mediaSource.streamUrl != "") {
player.source = streamUrl
}
}
}
Connections {
target: player
onPlaybackStateChanged: mediaSource.state = player.playbackState
onPositionChanged: mediaSource.position = Utils.msToTicks(player.position)
}
VideoOutput {
id: videoOutput
source: player
@ -81,7 +69,8 @@ SilicaItem {
Label {
anchors.fill: parent
anchors.margins: Theme.horizontalPageMargin
text: itemId + "\n" + mediaSource.streamUrl + "\n"
text: item.jellyfinId + "\n" + mediaSource.streamUrl + "\n"
+ player.position + "\n"
+ player.status + "\n"
+ player.bufferProgress + "\n"
+ player.metaData.videoCodec + "@" + player.metaData.videoFrameRate + "(" + player.metaData.videoBitRate + ")" + "\n"
@ -89,7 +78,7 @@ SilicaItem {
+ player.errorString + "\n"
font.pixelSize: Theme.fontSizeExtraSmall
wrapMode: "WordWrap"
visible: false
visible: true
}
}
@ -101,18 +90,4 @@ SilicaItem {
function stop() {
player.stop()
}
Connections {
property bool enabled: true
id: playerReadyToSeek
target: player
onPlaybackStateChanged: {
if (!enabled) return;
if (startTicks > 0 && player.playbackState == MediaPlayer.PlayingState) {
console.log("Seeking to " + Utils.ticksToMs(startTicks))
player.seek(Utils.ticksToMs(startTicks))
playerReadyToSeek.enabled = false // Only seek the first time this property changes
}
}
}
}

View file

@ -21,6 +21,8 @@ import Sailfish.Silica 1.0
import "../components"
import nl.netsoj.chris.Jellyfin 1.0
/**
* Page only containing a video player.
*
@ -29,11 +31,10 @@ import "../components"
Page {
id: videoPage
property string itemId
property var itemData
property JellyfinItem itemData
property int audioTrack
property int subtitleTrack
property real startTicks: 0 // Why is this a real? Because an integer only goes to 3:44 when the ticks are converted to doubles
property bool resume: true
allowedOrientations: Orientation.All
showNavigationIndicator: videoPlayer.hudVisible
@ -41,12 +42,12 @@ Page {
VideoPlayer {
id: videoPlayer
anchors.fill: parent
itemId: videoPage.itemId
player: appWindow.mediaPlayer
title: itemData.name
audioTrack: videoPage.audioTrack
subtitleTrack: videoPage.subtitleTrack
startTicks: videoPage.startTicks
resume: videoPage.resume
item: itemData
onLandscapeChanged: {
console.log("Is landscape: " + landscape)

View file

@ -62,7 +62,7 @@ Page {
id: backdropBackground
ThemeBackground {
sourceItem: backdrop
backgroundMaterial: Materials.blur
backgroundMaterial: "blur"
}
}

View file

@ -60,11 +60,10 @@ BaseDetailPage {
favourited: itemData.userData.isFavorite
playProgress: itemData.userData.playedPercentage / 100
onPlayPressed: pageStack.push(Qt.resolvedUrl("../VideoPage.qml"),
{"itemId": itemId, "itemData": itemData,
{"itemData": itemData,
"audioTrack": trackSelector.audioTrack,
"subtitleTrack": trackSelector.subtitleTrack,
"startTicks": startFromBeginning ? 0.0
: _playbackProsition })
"resume": resume})
}
VideoTrackSelector {