Skip to content

Commit

Permalink
Fix playing tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed Oct 28, 2020
1 parent c8154de commit 05903a4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 5 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const playbackChanged = () => {
footer.repeat.checked = playback["repeat"] !== "off"
}

const playTrack = id => {
let status = spotify.playTracksWithContext(`spotify:track:${id}`, root.currentContext)
const playTrack = index => {
let status = spotify.playTracksWithContext(index, root.currentContext)
if (status) {
console.log(status)
} else {
Expand All @@ -36,12 +36,14 @@ const playTrack = id => {

const loadTracks = tracks => {
trackListModel.clear()
let i = 0
tracks.forEach(track => trackListModel.append({
"id": track["id"],
"artist": track["artist"],
"track": track["name"],
"artistId": track["artist_id"],
"albumId": track["album_id"]
"albumId": track["album_id"],
"index": i++
}))
}

Expand Down
2 changes: 1 addition & 1 deletion qml/TrackListItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Button {

property var itemModel

onClicked: JS.playTrack(model.id)
onClicked: root.playTrack(itemModel.index)
readonly property var foregroundColor: currentTrackId === itemModel.id
? Material.accent : undefined

Expand Down
4 changes: 4 additions & 0 deletions qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ ApplicationWindow {
JS.loadArtist(id)
}

function playTrack(index) {
JS.playTrack(index)
}

Utils {
id: utils
}
Expand Down

0 comments on commit 05903a4

Please sign in to comment.