From 1b88ee3e01adef352fa736c5c53dc993996383bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Conrad=20H=C3=BCbler?= Date: Tue, 31 Dec 2024 15:45:10 +0100 Subject: [PATCH] general playlist might work better now MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Conrad Hübler --- qml/components/MediaController.qml | 6 +- qml/components/PlaylistManager.qml | 15 ++- qml/cover/CoverPage.qml | 200 +++++++++++++++++++++-------- qml/harbour-tidalplayer.qml | 15 ++- qml/pages/FirstPage.qml | 4 +- qml/pages/widgets/MiniPlayer.qml | 26 ++-- qml/playlistmanager.py | 2 +- 7 files changed, 192 insertions(+), 76 deletions(-) diff --git a/qml/components/MediaController.qml b/qml/components/MediaController.qml index 3333ff7..b0a7fe1 100644 --- a/qml/components/MediaController.qml +++ b/qml/components/MediaController.qml @@ -7,6 +7,7 @@ Item { // signals signal currentTrackChanged() + signal currentPosition(double position) property string current_track_title : "" property string current_track_artist : "" @@ -76,7 +77,6 @@ Item { property bool videoPlaying: false property string errorMsg: "" - signal currentPosition(int position) onError: { if (error === MediaPlayer.ResourceError) errorMsg = qsTr("Error: Problem with allocating resources") @@ -101,7 +101,7 @@ Item { } onPositionChanged: { - mediaPlayer.currentPosition(mediaPlayer.position/mediaPlayer.duration*100) + root.currentPosition(mediaPlayer.position/mediaPlayer.duration*100) } onPlaying: { @@ -169,7 +169,7 @@ Item { } function playUrl(url) { - console.log("only this function is allowed to start playback") + console.log("only this function is allowed to start playback", url) mediaPlayer.source = url mediaPlayer.play() } diff --git a/qml/components/PlaylistManager.qml b/qml/components/PlaylistManager.qml index a81145d..ff891c8 100644 --- a/qml/components/PlaylistManager.qml +++ b/qml/components/PlaylistManager.qml @@ -6,8 +6,8 @@ Item { //property var currentPlaylist: [] property int currentIndex: -1 - property bool canNext: false //currentPlaylist.length > 0 && currentIndex < currentPlaylist.length - 1 - property bool canPrev: false //currentIndex > 0 + property bool canNext: size > 0 && currentIndex < size - 1 + property bool canPrev: currentIndex > 0 property int size: 0 //currentPlaylist.length property int current_track: -1 property int tidalId : 0 @@ -21,7 +21,6 @@ Item { signal clearList() signal currentTrack(int position) - signal listFinished() signal listChanged() @@ -107,6 +106,7 @@ Item { call("playlistmanager.PL.PlaylistIndex", [], function(index){ current_track = index }) + } function getSize() { @@ -137,7 +137,7 @@ Item { } function nextTrack() { - call('playlistmanager.PL.NextTrack', {}) + call_sync('playlistmanager.PL.NextTrack', {}) } function previousTrack() { @@ -230,12 +230,13 @@ Item { } function nextTrack() { - console.log("Next track called") - if(mediaController.playbackState !== 1) { + console.log("Next track called", mediaController.playbackState) + //if(mediaController.playbackState !== 1) { playlistPython.canNext = false playlistPython.nextTrack() - } + //} currentTrackIndex() + //playTrack() } function nextTrackClicked() { diff --git a/qml/cover/CoverPage.qml b/qml/cover/CoverPage.qml index bc946cb..dac07e9 100644 --- a/qml/cover/CoverPage.qml +++ b/qml/cover/CoverPage.qml @@ -2,52 +2,131 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 CoverBackground { + id: cover + + property bool isPlaying: coverImage.source != "" + property var application + property var home + Image { + id: defaultLogo + visible: !isPlaying + source: "/usr/share/icons/hicolor/86x86/apps/harbour-tidalplayer.png" + anchors.centerIn: parent + width: parent.width * 0.5 + height: width + opacity: 0.6 + } + + Image { + id: backgroundImage + anchors.fill: parent + source: coverImage.source + fillMode: Image.PreserveAspectCrop + opacity: 0.1 + asynchronous: true + } + + Rectangle { + id: gradient + anchors.fill: parent + gradient: Gradient { + GradientStop { position: 0.0; color: "transparent" } + GradientStop { position: 1.0; color: Theme.rgba(Theme.primaryColor, 0.1) } + } + } Image { id: coverImage - width: 0.66 * parent.height - //anchors.centerIn: parent.top + width: parent.width - 2 * Theme.paddingMedium + height: width + anchors { + top: parent.top + topMargin: Theme.paddingLarge + horizontalCenter: parent.horizontalCenter + } fillMode: Image.PreserveAspectFit - anchors.margins: Theme.paddingSmall + asynchronous: true + visible: source != "" + + Rectangle { + color: Theme.rgba(Theme.highlightBackgroundColor, 0.1) + anchors.fill: parent + visible: coverImage.status !== Image.Ready && coverImage.source != "" + } } + Column { - anchors.top: coverImage.bottom - Label { - id: titleLabel - //anchors.bottom: parent - text: qsTr("Tidal Player") - color: Theme.highlightColor - anchors.margins: Theme.paddingSmall - anchors.top: coverImage.bottom - } - Label { - id: artist_albumLabel - //anchors.bottom: parent - color: Theme.highlightColor - anchors.margins: Theme.paddingSmall - anchors.top: titleLabel.bottom + anchors { + top: coverImage.source ? coverImage.bottom : parent.verticalCenter + topMargin: Theme.paddingMedium + left: parent.left + right: parent.right + leftMargin: Theme.paddingMedium + rightMargin: Theme.paddingMedium + } + spacing: Theme.paddingSmall + + Label { + id: titleLabel + width: parent.width + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.fontSizeMedium + color: Theme.primaryColor + truncationMode: TruncationMode.Fade + maximumLineCount: 2 + wrapMode: Text.Wrap + text: qsTr("Tidal Player") + } + + Label { + id: artist_albumLabel + width: parent.width + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.fontSizeSmall + color: Theme.secondaryColor + truncationMode: TruncationMode.Fade + maximumLineCount: 2 + wrapMode: Text.Wrap + text: qsTr("No track playing") + } } + + Row { + anchors { + horizontalCenter: parent.horizontalCenter + bottom: parent.bottom + bottomMargin: Theme.paddingLarge + } + spacing: Theme.paddingMedium + visible: !isPlaying + + Label { + text: qsTr("Tap to navigate") + color: Theme.secondaryColor + font.pixelSize: Theme.fontSizeExtraSmall + } } + CoverActionList { - id: coverAction + id: playbackActions + enabled: isPlaying + CoverAction { id: prevButton - iconSource: "image://theme/icon-m-simple-previous" + iconSource: "image://theme/icon-cover-previous" onTriggered: { mediaController.blockAutoNext = true playlistManager.previousTrack() } } + CoverAction { - iconSource: "image://theme/icon-m-simple-play" id: playpause - onTriggered: - { - if (mediaController.playbackState === 1) - { + iconSource: "image://theme/icon-cover-play" + onTriggered: { + if (mediaController.playbackState === 1) { mediaController.pause() - } - else if(mediaController.playbackState === 2){ + } else if(mediaController.playbackState === 2) { mediaController.play() } } @@ -55,49 +134,70 @@ CoverBackground { CoverAction { id: nextButton - iconSource: "image://theme/icon-m-simple-next" + iconSource: "image://theme/icon-cover-next" onTriggered: { mediaController.blockAutoNext = true playlistManager.nextTrackClicked() } } + } + + CoverActionList { + id: navigationActions + enabled: !isPlaying + + + CoverAction { + iconSource: "image://theme/icon-m-home" // Icon für Playlists + onTriggered: { + application.activate() + home.currentIndex = 0 // Playlists Tab + } + } CoverAction { - iconSource: "image://theme/icon-cover-search" + iconSource: "image://theme/icon-m-search" + onTriggered: { + application.activate() + home.currentIndex = 1 // Search Tab + } + } + CoverAction { + iconSource: "image://theme/icon-m-media-playlists" // Icon für Current + onTriggered: { + application.activate() + home.currentIndex = 2 // Current Tab + } } } - Connections - { + Connections { target: tidalApi - onCurrentPlayback: - { - titleLabel.text = trackinfo.track_num + " - " + trackinfo.title - artist_albumLabel.text = trackinfo.album + " - " + trackinfo.artist + onCurrentPlayback: { + titleLabel.text = trackinfo.title + artist_albumLabel.text = trackinfo.artist + "\n" + trackinfo.album coverImage.source = trackinfo.image } } - Connections - { + + Connections { target: playlistManager - onPlayListFinished: - { - titleLabel.text = "" - artist_albumLabel.text = "" + onPlayListFinished: { + titleLabel.text = qsTr("Tidal Player") + artist_albumLabel.text = qsTr("No track playing") coverImage.source = "" - prevButton.enabled = playlistManager.canPrev; - nextButton.enabled = playlistManager.canNext; + prevButton.enabled = playlistManager.canPrev + nextButton.enabled = playlistManager.canNext } } - Connections - { + + Connections { target: mediaController - onPlaybackStateChanged: - { + onPlaybackStateChanged: { if(mediaController.playbackState === 1) - playpause.iconSource = "image://theme/icon-m-simple-pause" - else if(mediaController.playbackState === 2) - playpause.iconSource = "image://theme/icon-m-simple-play" + playpause.iconSource = "image://theme/icon-cover-pause" + else if(mediaController.playbackState === 2) + playpause.iconSource = "image://theme/icon-cover-play" } } } diff --git a/qml/harbour-tidalplayer.qml b/qml/harbour-tidalplayer.qml index 649685c..2182d4e 100644 --- a/qml/harbour-tidalplayer.qml +++ b/qml/harbour-tidalplayer.qml @@ -6,13 +6,15 @@ import org.nemomobile.mpris 1.0 import Nemo.Configuration 1.0 import "components" - +import "cover" import "pages" import "pages/widgets" ApplicationWindow { + id: applicationWindow + //property alias firstPage: firstpage // Property für FirstPage property bool loginTrue : false property var locale: Qt.locale() property date currentDate: new Date() @@ -70,8 +72,15 @@ ApplicationWindow id: mediaController } - initialPage: Component { FirstPage { } } - cover: Qt.resolvedUrl("cover/CoverPage.qml") + initialPage: Component { + FirstPage { + id: firstpage // Diese ID wird nun über applicationWindow.firstPage verfügbar + } + } + cover: CoverPage { + application: applicationWindow + home : firstpage + } allowedOrientations: defaultAllowedOrientations diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 5eb4414..bc653bd 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -7,11 +7,11 @@ import "widgets" import "stuff" Page { - id: searchPage + id: firstPage // The effective value will be restricted by ApplicationWindow.allowedOrientations allowedOrientations: Orientation.All - + property int currentIndex : 0 // To enable PullDownMenu, place our content in a SilicaFlickable SilicaFlickable { clip: true diff --git a/qml/pages/widgets/MiniPlayer.qml b/qml/pages/widgets/MiniPlayer.qml index ebdae07..46a1fa5 100644 --- a/qml/pages/widgets/MiniPlayer.qml +++ b/qml/pages/widgets/MiniPlayer.qml @@ -102,7 +102,7 @@ DockedPanel { IconButton { id: prevButton icon.source: "image://theme/icon-m-previous" - //visible: playlistManager.canPrev + visible: playlistManager.canPrev onClicked: { console.log("prev button pressed") @@ -126,7 +126,7 @@ DockedPanel { IconButton { id: nextButton icon.source: "image://theme/icon-m-next" - //visible: playlistManager.canNext + visible: playlistManager.canNext onClicked: { console.log("next button pressed") @@ -154,10 +154,16 @@ DockedPanel { width: parent.width minimumValue: 0 maximumValue: 100 + enabled: mediaController.duration > 0 visible: false height: Theme.paddingMedium } - + Connections { + target: progressSlider + onReleased: { + mediaController.seek(progressSlider.value/100*mediaController.duration) + } + } // Zeitanzeige Row { id: timeRow @@ -199,19 +205,14 @@ DockedPanel { Connections { target: mediaController - onCurrentPosition: { - progressSlider.value = position - } + onPlaybackStateChanged: { if(mediaController.playbackState === 1) playButton.icon.source = "image://theme/icon-m-pause" else if(mediaController.playbackState === 2) playButton.icon.source = "image://theme/icon-m-play" } - } - Connections { - target: mediaController /* onCurrentTrack: { mediaTitle.text = track_num + " - " + mediaController.current_track_title @@ -224,12 +225,17 @@ DockedPanel { //nextButton.enabled = playlistManager.canNext progressSlider.visible = true }*/ + onCurrentPosition: { + if (!progressSlider.pressed) { // Nur updaten wenn der Slider nicht gedrückt ist + progressSlider.value = position + } + } } Connections { target: progressSlider onReleased: { - player.seek(progressSlider.value/100*mediaController.duration) + mediaController.seek(progressSlider.value/100*mediaController.duration) } } diff --git a/qml/playlistmanager.py b/qml/playlistmanager.py index 5c12a63..c59cb43 100644 --- a/qml/playlistmanager.py +++ b/qml/playlistmanager.py @@ -57,7 +57,7 @@ def NextTrack(self): if self.current_index < len(self.playlist) - 1: self.current_index += 1 self._notify_current_track() - #self._notify_playlist_state() + #self._notify_playlist_state() def PreviousTrack(self): """Wechselt zum vorherigen Track"""