mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-06 05:25:41 -05:00
fixes to media player position
This commit is contained in:
@@ -15,18 +15,20 @@ Rectangle {
|
|||||||
property string lastValidArtist: ""
|
property string lastValidArtist: ""
|
||||||
property string lastValidAlbum: ""
|
property string lastValidAlbum: ""
|
||||||
property string lastValidArtUrl: ""
|
property string lastValidArtUrl: ""
|
||||||
property real currentPosition: 0
|
property real currentPosition: activePlayer && activePlayer.positionSupported ? activePlayer.position : 0
|
||||||
|
|
||||||
function ratio() {
|
function ratio() {
|
||||||
return activePlayer
|
if (!activePlayer || activePlayer.length <= 0) {
|
||||||
&& activePlayer.length > 0 ? currentPosition / activePlayer.length : 0
|
return 0
|
||||||
|
}
|
||||||
|
let calculatedRatio = currentPosition / activePlayer.length
|
||||||
|
return Math.max(0, Math.min(1, calculatedRatio))
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivePlayerChanged: {
|
onActivePlayerChanged: {
|
||||||
if (!activePlayer)
|
if (activePlayer && activePlayer.positionSupported) {
|
||||||
updateTimer.start()
|
activePlayer.positionChanged()
|
||||||
else
|
}
|
||||||
updateTimer.stop()
|
|
||||||
}
|
}
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.height
|
height: parent.height
|
||||||
@@ -38,42 +40,39 @@ Rectangle {
|
|||||||
layer.enabled: true
|
layer.enabled: true
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: updateTimer
|
id: positionTimer
|
||||||
|
|
||||||
interval: 2000
|
interval: 500
|
||||||
running: {
|
running: activePlayer && activePlayer.playbackState === MprisPlaybackState.Playing
|
||||||
return (!activePlayer)
|
&& !progressMouseArea.isSeeking
|
||||||
|| (activePlayer
|
|
||||||
&& activePlayer.playbackState === MprisPlaybackState.Playing
|
|
||||||
&& activePlayer.length > 0 && !progressMouseArea.isSeeking)
|
|
||||||
}
|
|
||||||
repeat: true
|
repeat: true
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
if (!activePlayer) {
|
if (activePlayer && activePlayer.positionSupported) {
|
||||||
lastValidTitle = ""
|
activePlayer.positionChanged()
|
||||||
lastValidArtist = ""
|
|
||||||
lastValidAlbum = ""
|
|
||||||
lastValidArtUrl = ""
|
|
||||||
stop() // Stop after clearing cache
|
|
||||||
} else if (activePlayer.playbackState === MprisPlaybackState.Playing
|
|
||||||
&& !progressMouseArea.isSeeking) {
|
|
||||||
currentPosition = activePlayer.position
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: cleanupTimer
|
||||||
|
|
||||||
|
interval: 2000
|
||||||
|
running: !activePlayer
|
||||||
|
onTriggered: {
|
||||||
|
lastValidTitle = ""
|
||||||
|
lastValidArtist = ""
|
||||||
|
lastValidAlbum = ""
|
||||||
|
lastValidArtUrl = ""
|
||||||
|
currentPosition = 0
|
||||||
|
stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
function onPositionChanged() {
|
function onTrackChanged() {
|
||||||
if (!progressMouseArea.isSeeking)
|
if (activePlayer && activePlayer.positionSupported) {
|
||||||
currentPosition = activePlayer.position
|
activePlayer.positionChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPostTrackChanged() {
|
|
||||||
currentPosition = activePlayer && activePlayer.position || 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTrackTitleChanged() {
|
|
||||||
currentPosition = activePlayer && activePlayer.position || 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
target: activePlayer
|
target: activePlayer
|
||||||
@@ -238,7 +237,7 @@ Rectangle {
|
|||||||
height: parent.height
|
height: parent.height
|
||||||
radius: parent.radius
|
radius: parent.radius
|
||||||
color: Theme.primary
|
color: Theme.primary
|
||||||
width: parent.width * ratio()
|
width: Math.max(0, Math.min(parent.width, parent.width * ratio()))
|
||||||
|
|
||||||
Behavior on width {
|
Behavior on width {
|
||||||
NumberAnimation {
|
NumberAnimation {
|
||||||
@@ -284,12 +283,11 @@ Rectangle {
|
|||||||
preventStealing: true
|
preventStealing: true
|
||||||
onPressed: function (mouse) {
|
onPressed: function (mouse) {
|
||||||
isSeeking = true
|
isSeeking = true
|
||||||
if (activePlayer && activePlayer.length > 0) {
|
if (activePlayer && activePlayer.length > 0 && activePlayer.canSeek) {
|
||||||
let ratio = Math.max(0, Math.min(
|
let ratio = Math.max(0, Math.min(
|
||||||
1, mouse.x / progressBarBackground.width))
|
1, mouse.x / progressBarBackground.width))
|
||||||
let seekPosition = ratio * activePlayer.length
|
let seekPosition = ratio * activePlayer.length
|
||||||
activePlayer.position = seekPosition
|
activePlayer.position = seekPosition
|
||||||
currentPosition = seekPosition
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onReleased: {
|
onReleased: {
|
||||||
@@ -297,21 +295,19 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
onPositionChanged: function (mouse) {
|
onPositionChanged: function (mouse) {
|
||||||
if (pressed && isSeeking && activePlayer
|
if (pressed && isSeeking && activePlayer
|
||||||
&& activePlayer.length > 0) {
|
&& activePlayer.length > 0 && activePlayer.canSeek) {
|
||||||
let ratio = Math.max(0, Math.min(
|
let ratio = Math.max(0, Math.min(
|
||||||
1, mouse.x / progressBarBackground.width))
|
1, mouse.x / progressBarBackground.width))
|
||||||
let seekPosition = ratio * activePlayer.length
|
let seekPosition = ratio * activePlayer.length
|
||||||
activePlayer.position = seekPosition
|
activePlayer.position = seekPosition
|
||||||
currentPosition = seekPosition
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onClicked: function (mouse) {
|
onClicked: function (mouse) {
|
||||||
if (activePlayer && activePlayer.length > 0) {
|
if (activePlayer && activePlayer.length > 0 && activePlayer.canSeek) {
|
||||||
let ratio = Math.max(0, Math.min(
|
let ratio = Math.max(0, Math.min(
|
||||||
1, mouse.x / progressBarBackground.width))
|
1, mouse.x / progressBarBackground.width))
|
||||||
let seekPosition = ratio * activePlayer.length
|
let seekPosition = ratio * activePlayer.length
|
||||||
activePlayer.position = seekPosition
|
activePlayer.position = seekPosition
|
||||||
currentPosition = seekPosition
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -328,13 +324,12 @@ Rectangle {
|
|||||||
preventStealing: true
|
preventStealing: true
|
||||||
onPositionChanged: function (mouse) {
|
onPositionChanged: function (mouse) {
|
||||||
if (progressMouseArea.isSeeking && activePlayer
|
if (progressMouseArea.isSeeking && activePlayer
|
||||||
&& activePlayer.length > 0) {
|
&& activePlayer.length > 0 && activePlayer.canSeek) {
|
||||||
let globalPos = mapToItem(progressBarBackground, mouse.x, mouse.y)
|
let globalPos = mapToItem(progressBarBackground, mouse.x, mouse.y)
|
||||||
let ratio = Math.max(
|
let ratio = Math.max(
|
||||||
0, Math.min(1, globalPos.x / progressBarBackground.width))
|
0, Math.min(1, globalPos.x / progressBarBackground.width))
|
||||||
let seekPosition = ratio * activePlayer.length
|
let seekPosition = ratio * activePlayer.length
|
||||||
activePlayer.position = seekPosition
|
activePlayer.position = seekPosition
|
||||||
currentPosition = seekPosition
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onReleased: {
|
onReleased: {
|
||||||
@@ -379,9 +374,8 @@ Rectangle {
|
|||||||
if (!activePlayer)
|
if (!activePlayer)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (currentPosition > 8 && activePlayer.canSeek) {
|
if (activePlayer.position > 8 && activePlayer.canSeek) {
|
||||||
activePlayer.position = 0
|
activePlayer.position = 0
|
||||||
currentPosition = 0
|
|
||||||
} else {
|
} else {
|
||||||
activePlayer.previous()
|
activePlayer.previous()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user