mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 07:52:50 -05:00
media player: debounce on seek, fix binding issue, set cava source
This commit is contained in:
@@ -17,20 +17,32 @@ Rectangle {
|
|||||||
property string lastValidArtUrl: ""
|
property string lastValidArtUrl: ""
|
||||||
property real currentPosition: activePlayer
|
property real currentPosition: activePlayer
|
||||||
&& activePlayer.positionSupported ? activePlayer.position : 0
|
&& activePlayer.positionSupported ? activePlayer.position : 0
|
||||||
|
property real displayPosition: currentPosition
|
||||||
|
|
||||||
function ratio() {
|
function ratio() {
|
||||||
if (!activePlayer || activePlayer.length <= 0) {
|
if (!activePlayer || activePlayer.length <= 0) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
let calculatedRatio = currentPosition / activePlayer.length
|
let calculatedRatio = displayPosition / activePlayer.length
|
||||||
return Math.max(0, Math.min(1, calculatedRatio))
|
return Math.max(0, Math.min(1, calculatedRatio))
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivePlayerChanged: {
|
onActivePlayerChanged: {
|
||||||
if (activePlayer && activePlayer.positionSupported) {
|
if (activePlayer && activePlayer.positionSupported) {
|
||||||
activePlayer.positionChanged()
|
currentPosition = Qt.binding(() => activePlayer.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: positionTimer
|
||||||
|
interval: 300
|
||||||
|
running: activePlayer
|
||||||
|
&& activePlayer.playbackState === MprisPlaybackState.Playing
|
||||||
|
&& !progressMouseArea.isSeeking
|
||||||
|
repeat: true
|
||||||
|
onTriggered: activePlayer && activePlayer.positionSupported && activePlayer.positionChanged()
|
||||||
|
}
|
||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.height
|
height: parent.height
|
||||||
radius: Theme.cornerRadius
|
radius: Theme.cornerRadius
|
||||||
@@ -41,20 +53,6 @@ Rectangle {
|
|||||||
border.width: 1
|
border.width: 1
|
||||||
layer.enabled: true
|
layer.enabled: true
|
||||||
|
|
||||||
Timer {
|
|
||||||
id: positionTimer
|
|
||||||
|
|
||||||
interval: 500
|
|
||||||
running: activePlayer
|
|
||||||
&& activePlayer.playbackState === MprisPlaybackState.Playing
|
|
||||||
&& !progressMouseArea.isSeeking
|
|
||||||
repeat: true
|
|
||||||
onTriggered: {
|
|
||||||
if (activePlayer && activePlayer.positionSupported) {
|
|
||||||
activePlayer.positionChanged()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: cleanupTimer
|
id: cleanupTimer
|
||||||
@@ -71,15 +69,6 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
|
||||||
function onTrackChanged() {
|
|
||||||
if (activePlayer && activePlayer.positionSupported) {
|
|
||||||
activePlayer.positionChanged()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
target: activePlayer
|
|
||||||
}
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@@ -282,6 +271,21 @@ Rectangle {
|
|||||||
id: progressMouseArea
|
id: progressMouseArea
|
||||||
|
|
||||||
property bool isSeeking: false
|
property bool isSeeking: false
|
||||||
|
property real pendingSeekPosition: -1
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: seekDebounceTimer
|
||||||
|
interval: 150
|
||||||
|
repeat: false
|
||||||
|
onTriggered: {
|
||||||
|
if (progressMouseArea.pendingSeekPosition >= 0 && activePlayer && activePlayer.canSeek && activePlayer.length > 0) {
|
||||||
|
let clampedPosition = Math.min(progressMouseArea.pendingSeekPosition, activePlayer.length * 0.99)
|
||||||
|
activePlayer.position = clampedPosition
|
||||||
|
progressMouseArea.pendingSeekPosition = -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
@@ -297,12 +301,20 @@ Rectangle {
|
|||||||
0, Math.min(
|
0, Math.min(
|
||||||
1,
|
1,
|
||||||
mouse.x / progressBarBackground.width))
|
mouse.x / progressBarBackground.width))
|
||||||
let seekPosition = ratio * activePlayer.length
|
pendingSeekPosition = ratio * activePlayer.length
|
||||||
activePlayer.position = seekPosition
|
displayPosition = pendingSeekPosition
|
||||||
|
seekDebounceTimer.restart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onReleased: {
|
onReleased: {
|
||||||
isSeeking = false
|
isSeeking = false
|
||||||
|
seekDebounceTimer.stop()
|
||||||
|
if (pendingSeekPosition >= 0 && activePlayer && activePlayer.canSeek && activePlayer.length > 0) {
|
||||||
|
let clampedPosition = Math.min(pendingSeekPosition, activePlayer.length * 0.99)
|
||||||
|
activePlayer.position = clampedPosition
|
||||||
|
pendingSeekPosition = -1
|
||||||
|
}
|
||||||
|
displayPosition = Qt.binding(() => currentPosition)
|
||||||
}
|
}
|
||||||
onPositionChanged: function (mouse) {
|
onPositionChanged: function (mouse) {
|
||||||
if (pressed && isSeeking && activePlayer
|
if (pressed && isSeeking && activePlayer
|
||||||
@@ -312,8 +324,9 @@ Rectangle {
|
|||||||
0, Math.min(
|
0, Math.min(
|
||||||
1,
|
1,
|
||||||
mouse.x / progressBarBackground.width))
|
mouse.x / progressBarBackground.width))
|
||||||
let seekPosition = ratio * activePlayer.length
|
pendingSeekPosition = ratio * activePlayer.length
|
||||||
activePlayer.position = seekPosition
|
displayPosition = pendingSeekPosition
|
||||||
|
seekDebounceTimer.restart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onClicked: function (mouse) {
|
onClicked: function (mouse) {
|
||||||
@@ -323,8 +336,7 @@ Rectangle {
|
|||||||
0, Math.min(
|
0, Math.min(
|
||||||
1,
|
1,
|
||||||
mouse.x / progressBarBackground.width))
|
mouse.x / progressBarBackground.width))
|
||||||
let seekPosition = ratio * activePlayer.length
|
activePlayer.position = ratio * activePlayer.length
|
||||||
activePlayer.position = seekPosition
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -349,12 +361,20 @@ Rectangle {
|
|||||||
0, Math.min(
|
0, Math.min(
|
||||||
1,
|
1,
|
||||||
globalPos.x / progressBarBackground.width))
|
globalPos.x / progressBarBackground.width))
|
||||||
let seekPosition = ratio * activePlayer.length
|
progressMouseArea.pendingSeekPosition = ratio * activePlayer.length
|
||||||
activePlayer.position = seekPosition
|
displayPosition = progressMouseArea.pendingSeekPosition
|
||||||
|
seekDebounceTimer.restart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onReleased: {
|
onReleased: {
|
||||||
progressMouseArea.isSeeking = false
|
progressMouseArea.isSeeking = false
|
||||||
|
seekDebounceTimer.stop()
|
||||||
|
if (progressMouseArea.pendingSeekPosition >= 0 && activePlayer && activePlayer.canSeek && activePlayer.length > 0) {
|
||||||
|
let clampedPosition = Math.min(progressMouseArea.pendingSeekPosition, activePlayer.length * 0.99)
|
||||||
|
activePlayer.position = clampedPosition
|
||||||
|
progressMouseArea.pendingSeekPosition = -1
|
||||||
|
}
|
||||||
|
displayPosition = Qt.binding(() => currentPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ Singleton {
|
|||||||
property list<int> values: Array(6)
|
property list<int> values: Array(6)
|
||||||
property int refCount: 0
|
property int refCount: 0
|
||||||
property bool cavaAvailable: false
|
property bool cavaAvailable: false
|
||||||
|
property string monitorSource: AudioService.sink && AudioService.sink.name ? AudioService.sink.name + ".monitor" : ""
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: cavaCheck
|
id: cavaCheck
|
||||||
@@ -30,7 +31,9 @@ Singleton {
|
|||||||
id: cavaProcess
|
id: cavaProcess
|
||||||
|
|
||||||
running: root.cavaAvailable && root.refCount > 0
|
running: root.cavaAvailable && root.refCount > 0
|
||||||
command: ["sh", "-c", `printf '[general]\\nmode=normal\\nframerate=25\\nautosens=0\\nsensitivity=30\\nbars=6\\nlower_cutoff_freq=50\\nhigher_cutoff_freq=12000\\n[output]\\nmethod=raw\\nraw_target=/dev/stdout\\ndata_format=ascii\\nchannels=mono\\nmono_option=average\\n[smoothing]\\nnoise_reduction=35\\nintegral=90\\ngravity=95\\nignore=2\\nmonstercat=1.5' | cava -p /dev/stdin`]
|
command: ["sh", "-c", root.monitorSource
|
||||||
|
? `printf '[general]\\nmode=normal\\nframerate=25\\nautosens=0\\nsensitivity=30\\nbars=6\\nlower_cutoff_freq=50\\nhigher_cutoff_freq=12000\\n[input]\\nmethod=pulse\\nsource=${root.monitorSource}\\n[output]\\nmethod=raw\\nraw_target=/dev/stdout\\ndata_format=ascii\\nchannels=mono\\nmono_option=average\\n[smoothing]\\nnoise_reduction=35\\nintegral=90\\ngravity=95\\nignore=2\\nmonstercat=1.5' | cava -p /dev/stdin`
|
||||||
|
: `printf '[general]\\nmode=normal\\nframerate=25\\nautosens=0\\nsensitivity=30\\nbars=6\\nlower_cutoff_freq=50\\nhigher_cutoff_freq=12000\\n[output]\\nmethod=raw\\nraw_target=/dev/stdout\\ndata_format=ascii\\nchannels=mono\\nmono_option=average\\n[smoothing]\\nnoise_reduction=35\\nintegral=90\\ngravity=95\\nignore=2\\nmonstercat=1.5' | cava -p /dev/stdin`]
|
||||||
|
|
||||||
onRunningChanged: {
|
onRunningChanged: {
|
||||||
if (!running) {
|
if (!running) {
|
||||||
|
|||||||
Reference in New Issue
Block a user