浏览代码

Fixed total song time sometimes being 0:00.

KrisVos130 9 年之前
父节点
当前提交
3ed5fb4f9c
共有 2 个文件被更改,包括 6 次插入6 次删除
  1. 5 5
      app/app.js
  2. 1 1
      app/templates/room.html

+ 5 - 5
app/app.js

@@ -525,11 +525,6 @@ if (Meteor.isClient) {
     });
 
     Template.room.helpers({
-        songDuration: function() {
-            var duration = Session.get("duration");
-            var d = moment.duration(duration, 'seconds');
-            return d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
-        },
         type: function() {
             var parts = location.href.split('/');
             var id = parts.pop().toLowerCase();
@@ -844,6 +839,7 @@ if (Meteor.isClient) {
     Meteor.subscribe("rooms");
 
     Template.room.onCreated(function () {
+        $("#time-total").text("0:00");
         Session.set("reportSong", false);
         Session.set("reportTitle", false);
         Session.set("reportAuthor", false);
@@ -882,6 +878,8 @@ if (Meteor.isClient) {
             Session.set("id", songData.id);
             $("#song-img").attr("src", songData.img);
             Session.set("duration", songData.duration);
+            var d = moment.duration(songData.duration, 'seconds');
+            $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
         }
 
         function resizeSeekerbar() {
@@ -914,6 +912,8 @@ if (Meteor.isClient) {
                             }
                         }, 200);
                         Session.set("duration", currentSong.duration);
+                        var d = moment.duration(currentSong.duration, 'seconds');
+                        $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
                         resizeSeekerbar();
                     });
                 } else {

+ 1 - 1
app/templates/room.html

@@ -36,7 +36,7 @@
                         </div>
                         <div id="song-info" class="col-md-4" style="margin-top:15px">
                           <img class="song-img" onError="this.src='http://static.boredpanda.com/blog/wp-content/uploads/2014/04/amazing-fox-photos-182.jpg'" id="song-img"/>
-                          <h2 class="room-title">{{{title}}} <small id="time-display">(<span id="time-elapsed"></span> / <span>{{songDuration}}</span>)</small></h2>
+                          <h2 class="room-title">{{{title}}} <small id="time-display">(<span id="time-elapsed"></span> / <span id="time-total"></span>)</small></h2>
                           <h2 class="room-artist">{{{artist}}}</h2>
                         </div>
                     </div>