mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
Clicking on a track in the queue will now play that track.
This commit is contained in:
parent
9233ac940b
commit
a24f1ba219
@ -5,6 +5,19 @@ var Queue = can.Control.extend({
|
|||||||
queueSongs: options.queueSongs,
|
queueSongs: options.queueSongs,
|
||||||
status: options.status
|
status: options.status
|
||||||
}));
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
|
playSong: function(pos) {
|
||||||
|
can.ajax({
|
||||||
|
url: '/api/control/play',
|
||||||
|
data: { pos: pos },
|
||||||
|
type: 'PUT'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
'li click': function(element, event) {
|
||||||
|
var pos = $(element).data('pos');
|
||||||
|
this.playSong(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,8 +6,8 @@ class Control
|
|||||||
[:play, :stop, :next, :previous, :pause]
|
[:play, :stop, :next, :previous, :pause]
|
||||||
end
|
end
|
||||||
|
|
||||||
def play
|
def play(pos = nil)
|
||||||
MPDConnection.mpd.play
|
MPDConnection.mpd.play(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
|
|||||||
@ -1,17 +1,18 @@
|
|||||||
require './models/mpd_connection'
|
require './models/mpd_connection'
|
||||||
|
|
||||||
class Song < Struct.new(:id, :artist, :album, :title, :playing)
|
class Song < Struct.new(:id, :artist, :album, :title, :pos, :playing)
|
||||||
|
|
||||||
def initialize(song, playing: false)
|
def initialize(song, pos: nil, playing: false)
|
||||||
self.id = song.id
|
self.id = song.id
|
||||||
self.artist = song.artist
|
self.artist = song.artist
|
||||||
self.album = song.album
|
self.album = song.album
|
||||||
self.title = song.title
|
self.title = song.title
|
||||||
|
self.pos = pos
|
||||||
self.playing = playing
|
self.playing = playing
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.queue
|
def self.queue
|
||||||
current_song = MPDConnection.mpd.status[:songid]
|
current_song = MPDConnection.mpd.status[:songid]
|
||||||
MPDConnection.mpd.queue.map { |song| self.new(song, playing: (song.id == current_song)) }
|
MPDConnection.mpd.queue.map { |song| self.new(song, playing: (song.id == current_song), pos: song.pos) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -89,6 +89,10 @@ class MPDClient < Sinatra::Base
|
|||||||
JSON({ data: Song.queue.map(&:to_h) })
|
JSON({ data: Song.queue.map(&:to_h) })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
put '/control/play' do
|
||||||
|
Control.play(params[:pos])
|
||||||
|
end
|
||||||
|
|
||||||
put '/control/:action' do
|
put '/control/:action' do
|
||||||
if Control.controls.include?(params[:action].to_sym)
|
if Control.controls.include?(params[:action].to_sym)
|
||||||
Control.send(params[:action])
|
Control.send(params[:action])
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<ol id="queue">
|
<ol id="queue">
|
||||||
<% list(queueSongs, function(song) { %>
|
<% list(queueSongs, function(song) { %>
|
||||||
<li id="<%= song.attr('id') %>" <%= song.attr('playing') ? 'class="playing"' : '' %>>
|
<li id="<%= song.attr('id') %>" data-pos="<%= song.attr('pos') %>" <%= song.attr('playing') ? 'class="playing"' : '' %>>
|
||||||
<p class="title"><%= song.attr('title') %></p>
|
<p class="title"><%= song.attr('title') %></p>
|
||||||
<p class="artist"><%= song.attr('artist') %></p>
|
<p class="artist"><%= song.attr('artist') %></p>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user