MediaPlayer: more robust display
This commit is contained in:
parent
474bade65c
commit
f0ef9ac7b0
2 changed files with 10 additions and 7 deletions
|
|
@ -58,7 +58,7 @@ NBox {
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: main
|
id: main
|
||||||
|
|
||||||
visible: MediaPlayer.currentPlayer
|
visible: MediaPlayer.currentPlayer && MediaPlayer.canPlay
|
||||||
spacing: Style.marginMedium * scaling
|
spacing: Style.marginMedium * scaling
|
||||||
|
|
||||||
// Player selector
|
// Player selector
|
||||||
|
|
@ -229,12 +229,14 @@ NBox {
|
||||||
// Progress bar
|
// Progress bar
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: progressBarBackground
|
id: progressBarBackground
|
||||||
|
visible: (MediaPlayer.currentPlayer && MediaPlayer.trackLength > 0)
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: 4 * scaling
|
height: 4 * scaling
|
||||||
radius: Style.radiusSmall * scaling
|
radius: Style.radiusSmall * scaling
|
||||||
color: Colors.mSurfaceVariant
|
color: Colors.mSurface
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
|
||||||
property real progressRatio: {
|
property real progressRatio: {
|
||||||
if (!MediaPlayer.currentPlayer || !MediaPlayer.isPlaying || MediaPlayer.trackLength <= 0) {
|
if (!MediaPlayer.currentPlayer || !MediaPlayer.isPlaying || MediaPlayer.trackLength <= 0) {
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -259,17 +261,15 @@ NBox {
|
||||||
// Interactive progress handle
|
// Interactive progress handle
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: progressHandle
|
id: progressHandle
|
||||||
|
visible: (MediaPlayer.currentPlayer && MediaPlayer.trackLength > 0)
|
||||||
width: 16 * scaling
|
width: 16 * scaling
|
||||||
height: 16 * scaling
|
height: 16 * scaling
|
||||||
radius: width * 0.5
|
radius: width * 0.5
|
||||||
color: Colors.mPrimary
|
color: Colors.mPrimary
|
||||||
border.color: Colors.mSurface
|
border.color: Colors.mSurface
|
||||||
border.width: Math.max(1 * Style.borderMedium * scaling)
|
border.width: Math.max(1 * Style.borderMedium * scaling)
|
||||||
|
|
||||||
x: Math.max(0, Math.min(parent.width - width, progressFill.width - width / 2))
|
x: Math.max(0, Math.min(parent.width - width, progressFill.width - width / 2))
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
visible: MediaPlayer.trackLength > 0
|
|
||||||
scale: progressMouseArea.containsMouse || progressMouseArea.pressed ? 1.2 : 1.0
|
scale: progressMouseArea.containsMouse || progressMouseArea.pressed ? 1.2 : 1.0
|
||||||
|
|
||||||
Behavior on scale {
|
Behavior on scale {
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@ Singleton {
|
||||||
property string trackArtist: currentPlayer ? (currentPlayer.trackArtist || "") : ""
|
property string trackArtist: currentPlayer ? (currentPlayer.trackArtist || "") : ""
|
||||||
property string trackAlbum: currentPlayer ? (currentPlayer.trackAlbum || "") : ""
|
property string trackAlbum: currentPlayer ? (currentPlayer.trackAlbum || "") : ""
|
||||||
property string trackArtUrl: currentPlayer ? (currentPlayer.trackArtUrl || "") : ""
|
property string trackArtUrl: currentPlayer ? (currentPlayer.trackArtUrl || "") : ""
|
||||||
property real trackLength: currentPlayer ? currentPlayer.length : 0
|
property real trackLength: currentPlayer ? ((currentPlayer.length < infiniteTrackLength) ? currentPlayer.length : 0) : 0
|
||||||
property bool canPlay: currentPlayer ? currentPlayer.canPlay : false
|
property bool canPlay: currentPlayer ? currentPlayer.canPlay : false
|
||||||
property bool canPause: currentPlayer ? currentPlayer.canPause : false
|
property bool canPause: currentPlayer ? currentPlayer.canPause : false
|
||||||
property bool canGoNext: currentPlayer ? currentPlayer.canGoNext : false
|
property bool canGoNext: currentPlayer ? currentPlayer.canGoNext : false
|
||||||
property bool canGoPrevious: currentPlayer ? currentPlayer.canGoPrevious : false
|
property bool canGoPrevious: currentPlayer ? currentPlayer.canGoPrevious : false
|
||||||
property bool canSeek: currentPlayer ? currentPlayer.canSeek : false
|
property bool canSeek: currentPlayer ? currentPlayer.canSeek : false
|
||||||
property bool hasPlayer: getAvailablePlayers().length > 0
|
property real infiniteTrackLength: 922337203685
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
updateCurrentPlayer()
|
updateCurrentPlayer()
|
||||||
|
|
@ -49,6 +49,7 @@ Singleton {
|
||||||
function findActivePlayer() {
|
function findActivePlayer() {
|
||||||
let availablePlayers = getAvailablePlayers()
|
let availablePlayers = getAvailablePlayers()
|
||||||
if (availablePlayers.length === 0) {
|
if (availablePlayers.length === 0) {
|
||||||
|
console.log("[MediaPlayer] No active player found")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,6 +67,7 @@ Singleton {
|
||||||
if (newPlayer !== currentPlayer) {
|
if (newPlayer !== currentPlayer) {
|
||||||
currentPlayer = newPlayer
|
currentPlayer = newPlayer
|
||||||
currentPosition = currentPlayer ? currentPlayer.position : 0
|
currentPosition = currentPlayer ? currentPlayer.position : 0
|
||||||
|
console.log("[MediaPlayer] Switching player")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,6 +148,7 @@ Singleton {
|
||||||
Connections {
|
Connections {
|
||||||
target: Mpris.players
|
target: Mpris.players
|
||||||
function onValuesChanged() {
|
function onValuesChanged() {
|
||||||
|
console.log("[MediaPlayer] Players changed")
|
||||||
updateCurrentPlayer()
|
updateCurrentPlayer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue