mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
Add scrubber.
This commit is contained in:
parent
a24f1ba219
commit
361933e1bb
@ -1,18 +0,0 @@
|
|||||||
#transport
|
|
||||||
position: fixed
|
|
||||||
bottom: 0
|
|
||||||
width: 20em
|
|
||||||
background: rgba(248, 248, 248, 0.9)
|
|
||||||
border-top: 1px solid rgba(0, 0, 0, 0.1)
|
|
||||||
text-align: center
|
|
||||||
button
|
|
||||||
@extend .icon
|
|
||||||
font-size: 2em
|
|
||||||
width: 23%
|
|
||||||
padding: 0.5em
|
|
||||||
text-align: center
|
|
||||||
border: none
|
|
||||||
background: none
|
|
||||||
color: black
|
|
||||||
&:hover, &:focus
|
|
||||||
text-shadow: 0 0 10px rgba(255, 255, 255, 1)
|
|
||||||
@ -3,5 +3,5 @@
|
|||||||
@import 'includes/fonts'
|
@import 'includes/fonts'
|
||||||
@import 'includes/colours'
|
@import 'includes/colours'
|
||||||
@import 'common'
|
@import 'common'
|
||||||
@import 'controls'
|
@import 'transport'
|
||||||
@import 'queue'
|
@import 'queue'
|
||||||
|
|||||||
@ -16,6 +16,12 @@
|
|||||||
white-space: nowrap
|
white-space: nowrap
|
||||||
overflow: hidden
|
overflow: hidden
|
||||||
text-overflow: ellipsis
|
text-overflow: ellipsis
|
||||||
|
.length
|
||||||
|
position: absolute
|
||||||
|
font-size: 0.8em
|
||||||
|
padding: 0.6em 0
|
||||||
|
right: 10px
|
||||||
|
top: 10px
|
||||||
li
|
li
|
||||||
position: relative
|
position: relative
|
||||||
padding: 10px
|
padding: 10px
|
||||||
@ -39,3 +45,5 @@
|
|||||||
top: 10px
|
top: 10px
|
||||||
padding: 0.3em
|
padding: 0.3em
|
||||||
content: "playing"
|
content: "playing"
|
||||||
|
.length
|
||||||
|
display: none
|
||||||
|
|||||||
42
assets/css/transport.css.sass
Normal file
42
assets/css/transport.css.sass
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#transport
|
||||||
|
position: fixed
|
||||||
|
bottom: 0
|
||||||
|
width: 20em
|
||||||
|
background: rgba(248, 248, 248, 0.95)
|
||||||
|
border-top: 1px solid rgba(0, 0, 0, 0.1)
|
||||||
|
text-align: center
|
||||||
|
button
|
||||||
|
@extend .icon
|
||||||
|
font-size: 2em
|
||||||
|
width: 23%
|
||||||
|
padding: 0.5em
|
||||||
|
text-align: center
|
||||||
|
border: none
|
||||||
|
background: none
|
||||||
|
color: black
|
||||||
|
&:hover, &:focus
|
||||||
|
text-shadow: 0 0 10px rgba(255, 255, 255, 1)
|
||||||
|
|
||||||
|
.scrubber
|
||||||
|
@include clearfix
|
||||||
|
padding: 0.5em 25px 0
|
||||||
|
.time
|
||||||
|
font-size: 0.8em
|
||||||
|
.elapsed
|
||||||
|
float: left
|
||||||
|
.total
|
||||||
|
float: right
|
||||||
|
|
||||||
|
.track
|
||||||
|
position: relative
|
||||||
|
width: 70%
|
||||||
|
margin: 0.25em auto
|
||||||
|
height: 7px
|
||||||
|
background: rgba(127, 127, 127, 0.2)
|
||||||
|
.marker
|
||||||
|
position: absolute
|
||||||
|
background: #FD2D57
|
||||||
|
margin-left: -1px
|
||||||
|
margin-top: -4px
|
||||||
|
width: 2px
|
||||||
|
height: 15px
|
||||||
@ -14,6 +14,9 @@ var Events = can.Construct.extend({
|
|||||||
case 'queue':
|
case 'queue':
|
||||||
queue.replace(response.data);
|
queue.replace(response.data);
|
||||||
break;
|
break;
|
||||||
|
case 'time':
|
||||||
|
status.attr('time', response.data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
var Queue = can.Control.extend({
|
var Queue = can.Control.extend({
|
||||||
|
|
||||||
init: function(element, options) {
|
init: function(element, options) {
|
||||||
element.html(can.view('views/queue.ejs', {
|
element.html(
|
||||||
|
can.view('views/queue.ejs', {
|
||||||
queueSongs: options.queueSongs,
|
queueSongs: options.queueSongs,
|
||||||
status: options.status
|
status: options.status
|
||||||
}));
|
},
|
||||||
|
{ formatLength: timeHelpers.formatLength }
|
||||||
|
));
|
||||||
},
|
},
|
||||||
|
|
||||||
playSong: function(pos) {
|
playSong: function(pos) {
|
||||||
|
|||||||
@ -2,7 +2,12 @@ var Transport = can.Control.extend({
|
|||||||
|
|
||||||
init: function(element, options) {
|
init: function(element, options) {
|
||||||
this.status = options.status;
|
this.status = options.status;
|
||||||
element.html(can.view('views/transport.ejs', { status: this.status }));
|
element.html(
|
||||||
|
can.view(
|
||||||
|
'views/transport.ejs', { status: this.status },
|
||||||
|
{ formatLength: timeHelpers.formatLength }
|
||||||
|
)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateStatus: function(status) {
|
updateStatus: function(status) {
|
||||||
|
|||||||
10
assets/js/helpers/time.js
Normal file
10
assets/js/helpers/time.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
window.timeHelpers = {
|
||||||
|
formatLength: function(length) {
|
||||||
|
var minutes = Math.floor(length / 60);
|
||||||
|
var seconds = length % 60;
|
||||||
|
if (seconds < 10) {
|
||||||
|
seconds = '0' + seconds;
|
||||||
|
}
|
||||||
|
return minutes + ':' + seconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@
|
|||||||
//= require ./libs/can.ejs.js
|
//= require ./libs/can.ejs.js
|
||||||
|
|
||||||
//= require_tree ./models/
|
//= require_tree ./models/
|
||||||
|
//= require_tree ./helpers/
|
||||||
//= require_tree ./controls/
|
//= require_tree ./controls/
|
||||||
//= require_tree ./constructs/
|
//= require_tree ./constructs/
|
||||||
//= require ./router.js
|
//= require ./router.js
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
require './models/mpd_connection'
|
require './models/mpd_connection'
|
||||||
|
|
||||||
class Song < Struct.new(:id, :artist, :album, :title, :pos, :playing)
|
class Song < Struct.new(:id, :artist, :album, :title, :length, :pos, :playing)
|
||||||
|
|
||||||
def initialize(song, pos: nil, 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.length = song.time
|
||||||
self.pos = pos
|
self.pos = pos
|
||||||
self.playing = playing
|
self.playing = playing
|
||||||
end
|
end
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class MPDClient < Sinatra::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.send_time(elapsed, total)
|
def self.send_time(elapsed, total)
|
||||||
response = JSON({ type: 'time', data: { elapsed: elapsed, total: total } })
|
response = JSON({ type: 'time', data: [elapsed, total] })
|
||||||
settings.connections.each { |out| out << "data: #{response}\n\n" }
|
settings.connections.each { |out| out << "data: #{response}\n\n" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
<li id="<%= song.attr('id') %>" data-pos="<%= song.attr('pos') %>" <%= 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>
|
||||||
|
<p class="length"><%= formatLength(song.attr('length')) %></p>
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
</ol>
|
</ol>
|
||||||
|
|||||||
@ -1,4 +1,13 @@
|
|||||||
<nav>
|
<% if (status.attr('time')) { %>
|
||||||
|
<div class="scrubber">
|
||||||
|
<div class="time elapsed"><%= formatLength(status.attr('time')[0]) %></div>
|
||||||
|
<div class="time total"><%= formatLength(status.attr('time')[1]) %></div>
|
||||||
|
<div class="track">
|
||||||
|
<div class="marker" style="left: <%= (status.attr('time')[0] / status.attr('time')[1]) * 100 %>%"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
|
<nav class="controls">
|
||||||
<button data-command="previous">previous</button>
|
<button data-command="previous">previous</button>
|
||||||
<% if (status.attr('state') == 'play') { %>
|
<% if (status.attr('state') == 'play') { %>
|
||||||
<button data-command="pause">pause</button>
|
<button data-command="pause">pause</button>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user