Permalink
Browse files

added show duration of track and position of radio

  • Loading branch information...
1 parent f030dfd commit 7d569ffbdf185dfa280586de2d0c9bb7ffad047c @msoap committed Feb 2, 2013
Showing with 45 additions and 4 deletions.
  1. +22 −2 mojolicious-radio-box.pl
  2. +23 −2 src/radio-box-client.coffee
View
24 mojolicious-radio-box.pl
@@ -492,6 +492,7 @@ sub _cmus_parse_info {
});
},
render_info: function() {
+ var duration, position;
$("button.nav_buttons").removeAttr('disabled');
if (App.info.status === 'playing') {
$("#bt_pause").html('<i class="icon-pause">&nbsp;&nbsp;pause');
@@ -504,9 +505,11 @@ sub _cmus_parse_info {
}
if (App.info.tag) {
if (App.info.radio_title) {
- $("#div_info").html("" + App.info.tag.title + "<br>\n<b>" + App.info.radio_title + "</b>");
+ position = parseInt(App.info.position) > 0 ? " (" + App.format_track_time(parseInt(App.info.position)) + ")" : "";
+ $("#div_info").html("" + App.info.tag.title + "<br>\n<b>" + App.info.radio_title + position + "</b>");
} else if (App.info.tag.artist && App.info.tag.album) {
- $("#div_info").html("" + App.info.tag.artist + "<br>\n<i>" + App.info.tag.album + "</i><br>\n<b>" + App.info.tag.title + "</b>");
+ duration = parseInt(App.info.duration) > 0 ? " (" + App.format_track_time(parseInt(App.info.duration)) + ")" : "";
+ $("#div_info").html("" + App.info.tag.artist + "<br>\n<i>" + App.info.tag.album + "</i><br>\n<b>" + App.info.tag.title + duration + "</b>");
$("#radio_stations").hide()[0].selectedIndex = 0;
} else {
$("#div_info").html("<b>" + App.info.tag.title + "</b>");
@@ -541,6 +544,23 @@ sub _cmus_parse_info {
}
return _results;
},
+ format_track_time: function(all_seconds) {
+ var hours, minutes, result, seconds;
+ hours = Math.floor(all_seconds / 3600);
+ minutes = Math.floor((all_seconds - hours * 3600) / 60);
+ seconds = (all_seconds - hours * 3600 - minutes * 60) % 60;
+ if (minutes < 10) {
+ minutes = "0" + minutes;
+ }
+ if (seconds < 10) {
+ seconds = "0" + seconds;
+ }
+ result = "" + minutes + ":" + seconds;
+ if (hours > 0) {
+ result = "" + hours + ":" + result;
+ }
+ return result;
+ },
do_pause: function() {
$("#bt_pause").attr('disabled', 'disabled');
if (App.info.duration > 0 && !App.info.radio_title) {
View
25 src/radio-box-client.coffee
@@ -49,17 +49,27 @@ window.App =
if App.info.tag
if App.info.radio_title
+ position = if parseInt(App.info.position) > 0
+ " (" + App.format_track_time(parseInt(App.info.position)) + ")"
+ else
+ ""
$("#div_info").html """
#{App.info.tag.title}<br>
- <b>#{App.info.radio_title}</b>
+ <b>#{App.info.radio_title}#{position}</b>
"""
+
else if App.info.tag.artist && App.info.tag.album
+ duration = if parseInt(App.info.duration) > 0
+ " (" + App.format_track_time(parseInt(App.info.duration)) + ")"
+ else
+ ""
$("#div_info").html """
#{App.info.tag.artist}<br>
<i>#{App.info.tag.album}</i><br>
- <b>#{App.info.tag.title}</b>
+ <b>#{App.info.tag.title}#{duration}</b>
"""
$("#radio_stations").hide()[0].selectedIndex = 0
+
else
$("#div_info").html """
<b>#{App.info.tag.title}</b>
@@ -88,6 +98,17 @@ window.App =
select_input.options.add(new_option)
# ...........................................
+ format_track_time: (all_seconds) ->
+ hours = Math.floor(all_seconds / 3600)
+ minutes = Math.floor((all_seconds - hours * 3600) / 60)
+ seconds = (all_seconds - hours * 3600 - minutes * 60) % 60
+ minutes = "0#{minutes}" if minutes < 10
+ seconds = "0#{seconds}" if seconds < 10
+ result = "#{minutes}:#{seconds}"
+ result = "#{hours}:#{result}" if hours > 0
+ return result
+
+ # events ....................................
do_pause: ->
$("#bt_pause").attr('disabled', 'disabled')
if App.info.duration > 0 && ! App.info.radio_title

0 comments on commit 7d569ff

Please sign in to comment.