Mpris and prev/next playlist functions

This commit is contained in:
nesnomis 2025-06-02 16:00:00 +02:00
parent 3e431edef9
commit f3c06d738f
5 changed files with 40 additions and 54 deletions

View File

@ -15,8 +15,8 @@ MprisPlayer {
canControl: true canControl: true
canGoNext: false //appstate.playlistIndex < appstate.playlist.count canGoNext: radioPlayer.playlistIndex < radioPlayer.playlist.count //true //appstate.playlistIndex < appstate.playlist.count
canGoPrevious: false // appstate.playlistIndex > 0 canGoPrevious: radioPlayer.playlistIndex > 0 // appstate.playlistIndex > 0
canPause: radioPlayer.isPlaying ? true : false canPause: radioPlayer.isPlaying ? true : false
canPlay: radioPlayer.isPaused ? true : false canPlay: radioPlayer.isPaused ? true : false
@ -32,23 +32,18 @@ MprisPlayer {
if (radioPlayer.isPlaying) Mpris.Playing; if (radioPlayer.isPlaying) Mpris.Playing;
else if (radioPlayer.isPaused) Mpris.Paused; else if (radioPlayer.isPaused) Mpris.Paused;
else Mpris.Stopped; else Mpris.Stopped;
/* switch (radioPlayer.playbackState) {
case Audio.PlayingState:
return Mpris.Playing
case Audio.PausedState:
return Mpris.Paused
default:
return Mpris.Stopped
}*/
} }
metaData { metaData {
url: radioPlayer.source url: radioPlayer.source
contributingArtist: radioPlayer.metaInfo contributingArtist: radioPlayer.metaData.title
title: radioPlayer._name title: radioPlayer._name
} }
onNextRequested: radioPlayer.playNext()
onPreviousRequested: radioPlayer.playPrev()
onPauseRequested:{ onPauseRequested:{
radioPlayer.pauseStream(); radioPlayer.pauseStream();
} }
@ -57,7 +52,7 @@ MprisPlayer {
radioPlayer.resumeStream(); radioPlayer.resumeStream();
} }
onPlayPauseRequested: { onPlayPauseRequested: {
radioPlayer.pauseStream(); radioPlayer.isPaused ? radioPlayer.playStream() : radioPlayer.pauseStream();
} }
onStopRequested: { onStopRequested: {
radioPlayer.pauseStream(); radioPlayer.pauseStream();

View File

@ -144,6 +144,17 @@ MediaPlayer {
} }
function playNext() {
playlistIndex < playlistCount && playlistIndex > -1 ? playlistIndex = playlistIndex + 1 : playlistIndex = 0
loadPlaylistSelected()
}
function playPrev() {
playlistIndex < playlistCount && playlistIndex > 0 ? playlistIndex = playlistIndex - 1 : playlistIndex = 0
loadPlaylistSelected()
}
function videoPause() { function videoPause() {
source = "" source = ""
stop() stop()

View File

@ -200,6 +200,22 @@ Page {
id: row id: row
anchors.centerIn: parent anchors.centerIn: parent
spacing: Theme.paddingMedium spacing: Theme.paddingMedium
Image {
id: playprev
enabled: radioPlayer.playlistIndex > 0
opacity: enabled ? 1.0 : 0.4
source: "image://theme/icon-m-previous"
height: play.height
width: height
fillMode: Image.PreserveAspectFit
anchors.verticalCenter: play.verticalCenter
MouseArea {
anchors.fill: parent
onClicked: {
radioPlayer.playPrev()
}
}
}
Image { Image {
id: play id: play
source: radioPlayer.isPlaying ? "image://theme/icon-l-pause" : "image://theme/icon-l-play" source: radioPlayer.isPlaying ? "image://theme/icon-l-pause" : "image://theme/icon-l-play"
@ -211,25 +227,23 @@ Page {
} }
} }
Image { Image {
id: playDLNA id: playDLNA
enabled: radioPlayer.playlistIndex < radioPlayer.playlist.count
opacity: enabled ? 1.0 : 0.4
source: "image://theme/icon-m-next" source: "image://theme/icon-m-next"
height: play.height height: play.height
width: height width: height
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
anchors.verticalCenter: play.verticalCenter anchors.verticalCenter: play.verticalCenter
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
console.log(radioPlayer.playlistIndex + " | "+radioPlayer.playlistCount) radioPlayer.playNext()
radioPlayer.playlistIndex < radioPlayer.playlistCount && radioPlayer.playlistIndex > -1 ? radioPlayer.playlistIndex = radioPlayer.playlistIndex + 1 : radioPlayer.playlistIndex = 0
radioPlayer.loadPlaylistSelected()
} }
} }
} }
Image { Image {
id: sleeptimer
source: "image://theme/icon-s-timer" source: "image://theme/icon-s-timer"
height: play.height height: play.height
width: height width: height
@ -239,22 +253,15 @@ Page {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
pageStack.push("SleepTimerPage.qml") pageStack.push("SleepTimerPage.qml")
/* console.log(radioPlayer.playlistIndex + " | "+radioPlayer.playlistCount)
if (radioPlayer.playlistIndex > -1) {
radioPlayer.playlistIndex > 0 ? radioPlayer.playlistIndex = radioPlayer.playlistIndex - 1 : radioPlayer.playlistIndex = 16
} else radioPlayer.playlistIndex = 0
radioPlayer.loadPlaylistSelected() */
} }
} }
} }
} }
} }
Rectangle { Rectangle {
visible: orientation === Orientation.Portrait visible: orientation === Orientation.Portrait
width: upvote.width + url.width + favorite.width + (Theme.paddingMedium * 4) width: upvote.width + favorite.width + (Theme.paddingMedium * 4)
height: upvote.height + (Theme.paddingMedium * 2) height: upvote.height + (Theme.paddingMedium * 2)
radius: 90 radius: 90
color: Theme.rgba(Theme.overlayBackgroundColor,0.5) color: Theme.rgba(Theme.overlayBackgroundColor,0.5)
@ -290,19 +297,6 @@ Page {
onClicked: {radioBrowser.upVote(radioPlayer._stationuuid,upvote.returnValue)} onClicked: {radioBrowser.upVote(radioPlayer._stationuuid,upvote.returnValue)}
} }
} }
Image {
id: url
source: "image://theme/icon-m-website"
height: favorite.height
width: height
fillMode: Image.PreserveAspectFit
MouseArea {
anchors.fill: parent
onClicked: {
statusInfo.visible = true;remorse.execute(statusInfo,qsTr("<h2>Open radio station webpage</h2>"), function() {Qt.openUrlExternally(radioPlayer._homepage)}, 5000)
}
}
}
} }
} }
} }

View File

@ -1069,13 +1069,6 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>RadioPlayerPage</name>
<message>
<source>&lt;h2&gt;Open radio station webpage&lt;/h2&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>SecondPage</name> <name>SecondPage</name>
<message> <message>

View File

@ -1069,13 +1069,6 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>RadioPlayerPage</name>
<message>
<source>&lt;h2&gt;Open radio station webpage&lt;/h2&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>SecondPage</name> <name>SecondPage</name>
<message> <message>