Skip to content

Commit c2b20b2

Browse files
committed
added track position slider on mains screen
1 parent 4e09b3d commit c2b20b2

4 files changed

Lines changed: 113 additions & 11 deletions

File tree

Changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
1.2.9
2+
- added position slider on the big screen to move position within a track
3+
14
1.2.8
25
- FIX: if the 'title' or 'artist' tag is missing the value from the previous track was still shown on the tile
36

MediaScreen.qml

Lines changed: 94 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Screen {
1616
property string itemType
1717
property int volumeState
1818
property alias queueTimerControl : queueTimer
19+
property alias positionIndicatorWidth : volumeBar.width
20+
property alias positionIndicatorLeft : volumeBar.left
21+
property bool positionIndicatorDragActive : falso
22+
property int positionIndicatorX
1923

2024
onCustomButtonClicked: {
2125
if (app.favoritesScreen) {
@@ -120,18 +124,17 @@ Screen {
120124
horizontalAlignment: Text.AlignHCenter
121125
anchors {
122126
top: parent.top
123-
topMargin: isNxt ? 350 : 280
127+
topMargin: isNxt ? 325 : 260
124128
left: parent.left
125-
leftMargin: isNxt ? 40 : 32
126129
}
127-
width: isNxt ? 250 : 200
130+
width: isNxt ? 325 : 260
128131
}
129132

130133
Text {
131134
id: itemText
132135

133136
text: app.actualTitle
134-
font.pixelSize: isNxt ? 20 : 16
137+
font.pixelSize: isNxt ? 15 : 12
135138
font.family: qfont.regular.name
136139
font.bold: true
137140
color: colors.tileTextColor
@@ -142,9 +145,8 @@ Screen {
142145
top: itemArtist.bottom
143146
topMargin: isNxt ? 5 : 4
144147
left: parent.left
145-
leftMargin: isNxt ? 40 : 32
146148
}
147-
width: isNxt ? 250 : 200
149+
width: isNxt ? 325 : 260
148150
}
149151

150152
//below you'll find the iconbuttons which are controlling your device (previous, play/pause, shuffle on and shuffle off and the next button)
@@ -242,7 +244,6 @@ Screen {
242244

243245
iconSource: "qrc:/tsc/right.png"
244246
onClicked: {
245-
console.log("next");
246247
app.simpleSynchronous("http://"+app.connectionPath+"/"+app.sonosName+"/next");
247248
}
248249
}
@@ -385,12 +386,95 @@ Screen {
385386
}
386387
}
387388

389+
//this is the picture behind the slider.
390+
Image {
391+
id: volumeBar
392+
source: "drawables/volumeBarTile.png"
393+
width: isNxt ? 325 : 260
394+
height: isNxt ? 20 : 16
395+
anchors {
396+
bottom: volumeDown.top
397+
bottomMargin: isNxt ? 20 : 16
398+
left: parent.left
399+
}
400+
visible: app.showSlider
401+
}
402+
403+
//this image is the slider indicator.
404+
Image {
405+
id: positionIndicator
406+
source: "drawables/volumeIndicator.png"
407+
height: isNxt ? 35 : 28
408+
width: isNxt ? 35 : 28
409+
x: positionIndicatorX
410+
y: isNxt ? 417 : 333
388411

389-
function pad(n, width) {
390-
n = n + '';
391-
return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
412+
MouseArea {
413+
id: mouseArea
414+
anchors.fill: parent
415+
drag {
416+
target: positionIndicator
417+
axis: Drag.XAxis
418+
minimumX: 0
419+
maximumX: isNxt ? 290 : 232
420+
}
421+
property bool dragActive: drag.active
422+
onDragActiveChanged: {
423+
if (!drag.active) {
424+
positionIndicatorDragActive = false;
425+
var xPos = positionIndicator.x;
426+
if (xPos < 0) xPos = 0;
427+
app.simpleSynchronous("http://"+app.connectionPath+"/"+app.sonosName+"/timeseek/" + Math.floor(xPos * app.trackDuration / volumeBar.width));
428+
app.showSlider = false;
429+
} else {
430+
positionIndicatorDragActive = true;
431+
}
432+
}
433+
}
434+
onXChanged: {
435+
if (mouseArea.drag.active) {
436+
app.trackElapsedTime = Math.floor(x * app.trackDuration / volumeBar.width);
437+
}
438+
}
439+
visible: app.showSlider
440+
}
441+
442+
Text {
443+
id: trackLength
444+
445+
text: new Date(app.trackDuration * 1000).toISOString().substr(14, 5)
446+
font.pixelSize: isNxt ? 13 : 10
447+
font.family: qfont.regular.name
448+
font.bold: true
449+
color: colors.tileTextColor
450+
451+
anchors {
452+
bottom: volumeBar.top
453+
bottomMargin: isNxt ? 5 : 4
454+
right: volumeBar.right
455+
rightMargin: isNxt ? -20 : -16
456+
}
457+
visible: app.showSlider
458+
}
459+
460+
Text {
461+
id: trackPositionTime
462+
463+
text: new Date(app.trackElapsedTime * 1000).toISOString().substr(14, 5)
464+
font.pixelSize: isNxt ? 13 : 10
465+
font.family: qfont.regular.name
466+
font.bold: true
467+
color: colors.tileTextColor
468+
469+
anchors {
470+
bottom: volumeBar.top
471+
bottomMargin: isNxt ? 5 : 4
472+
right: positionIndicator.right
473+
}
474+
visible: app.showSlider && ((positionIndicatorX / volumeBar.width) < 0.85)
392475
}
393476

477+
394478
//This function is to setup the playlist, export the information to: PlaylistItemsJS and configure the scrollable list (refresh and everything).
395479
function updateQueue() {
396480

SonosApp.qml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ App {
6363
property string messageSonosName : "Alle"
6464
property int messageVolume : 20
6565
property string messageText
66+
property int trackDuration
67+
property int trackElapsedTime
68+
property bool showSlider : false
69+
property bool showSliderTime : false
6670

6771
//this is the main property for the complete Sonos App!
6872
property string connectionPath
@@ -227,10 +231,19 @@ App {
227231
if (xmlhttp.status == 200) {
228232
var response = JSON.parse(xmlhttp.responseText);
229233
if (response['currentTrack']['type'] == "track"){
234+
showSlider = true;
235+
showSliderTime = true;
230236
actualArtist = "";
231237
actualTitle = "";
232238
if (response['currentTrack']['title']) actualTitle = response['currentTrack']['title'];
233239
if (response['currentTrack']['artist']) actualArtist = response['currentTrack']['artist'];
240+
if (response['currentTrack']['duration']) trackDuration = response['currentTrack']['duration'];
241+
if (response['elapsedTime']) {
242+
if (!mediaScreen.positionIndicatorDragActive) { //do not update elapsedTime when positionIndicator is being dragged
243+
trackElapsedTime = response['elapsedTime'];
244+
mediaScreen.positionIndicatorX = Math.floor((trackElapsedTime / trackDuration) * mediaScreen.positionIndicatorWidth);
245+
}
246+
}
234247
if ('absoluteAlbumArtUri' in response['currentTrack']) {
235248
var tmpNowPlayingImage = response['currentTrack']['absoluteAlbumArtUri'].replace("https://", "http://");
236249
} else {
@@ -241,6 +254,8 @@ App {
241254
}
242255
}
243256
if (response['currentTrack']['type'] == "radio"){
257+
showSlider = false;
258+
showSliderTime = false;
244259
actualArtist = response['currentTrack']['stationName'];
245260
actualTitle = "";
246261
if (response['playbackState'] == "PLAYING") {

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.8
1+
1.2.9

0 commit comments

Comments
 (0)