2
0
Эх сурвалжийг харах

added skip duration (for intros) on song edit

AkiraLaine 9 жил өмнө
parent
commit
8bce0fc580

+ 22 - 4
app/client/client.js

@@ -695,6 +695,18 @@ Template.admin.helpers({
 });
 
 Template.stations.helpers({
+    queues: function() {
+        var queues = Queues.find({}).fetch();
+        queues.map(function(queue) {
+            if (Rooms.find({type: queue.type}).count() !== 1) {
+                return;
+            } else {
+                queue.display = Rooms.findOne({type: queue.type}).display;
+                return queue;
+            }
+        });
+        return queues;
+    },
     playlists: function() {
         var playlists = Playlists.find({}).fetch();
         playlists.map(function(playlist) {
@@ -838,6 +850,10 @@ Template.stations.events({
         newSong.img = $("#img").val();
         newSong.type = $("#type").val();
         newSong.duration = $("#duration").val();
+        newSong.skipDuration = $("#skip-duration").val();
+        if(newSong.skipDuration === undefined){
+            newSong.skipDuration = 0;
+        };
         if (Session.get("type") === "playlist") {
             Meteor.call("updatePlaylistSong", Session.get("genre"), Session.get("song"), newSong, function() {
                 $('#editModal').modal('hide');
@@ -1031,18 +1047,21 @@ Template.room.onCreated(function () {
                         playerVars: {controls: 0, iv_load_policy: 3, rel: 0, showinfo: 0},
                         events: {
                             'onReady': function(event) {
-                                event.target.seekTo(getTimeElapsed() / 1000);
+                                if(currentSong.skipDuration === undefined){
+                                    currentSong.skipDuration = 0;
+                                }
+                                event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
                                 event.target.playVideo();
                                 event.target.setVolume(volume);
                                 resizeSeekerbar();
                             },
                             'onStateChange': function(event){
                                 if (event.data == YT.PlayerState.PAUSED && Session.get("state") === "playing") {
-                                    event.target.seekTo(getTimeElapsed() / 1000);
+                                    event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
                                     event.target.playVideo();
                                 }
                                 if (event.data == YT.PlayerState.PLAYING && Session.get("state") === "paused") {
-                                    event.target.seekTo(getTimeElapsed() / 1000);
+                                    event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
                                     event.target.pauseVideo();
                                 }
                             }
@@ -1095,7 +1114,6 @@ Template.room.onCreated(function () {
                     currentSong = room.currentSong.song;
                     currentSong.started = room.currentSong.started;
                     Session.set("currentSong", currentSong);
-
                     startSong();
                 }
 

+ 2 - 0
app/client/templates/stations.html

@@ -143,6 +143,8 @@
                       <input class="song-input" name="title" id="title" type="text" />
                       <label for="title" class="song-input-label">Song Duration</label>
                       <input class="song-input" name="duration" id="duration" type="number" />
+                      <label class="song-input-label">Skip Duration</label>
+                      <input class="song-input" id="skip-duration" type="number" />
                       <label for="img" class="song-input-label">Song Image</label>
                       <input class="song-input" name="img" id="img" type="text" />
                       <button type="button" id="get-spotify-info" class="button">Get Spotify Data</button>

+ 5 - 1
app/server/server.js

@@ -572,6 +572,7 @@ Meteor.methods({
                 if (songData !== undefined && Object.keys(songData).length === 5 && songData.type !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.img !== undefined) {
                     songData.duration = getSongDuration(songData.title, songData.artist);
                     songData.img = getSongAlbumArt(songData.title, songData.artist);
+                    songData.skipDuration = 0;
                     var mid = createUniqueSongId();
                     if (mid !== undefined) {
                         songData.mid = mid;
@@ -583,6 +584,7 @@ Meteor.methods({
                                     title: songData.title,
                                     artist: songData.artist,
                                     duration: songData.duration,
+                                    skipDuration: songData.skipDuration,
                                     img: songData.img,
                                     type: songData.type
                                 }
@@ -643,7 +645,8 @@ Meteor.methods({
                 if (Playlists.find({type: type}).count() === 0) {
                     Playlists.insert({type: type, songs: []});
                 }
-                if (songData !== undefined && Object.keys(songData).length === 7 && songData.type !== undefined && songData.mid !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.duration !== undefined && songData.img !== undefined) {
+                console.log(songData);
+                if (songData !== undefined && Object.keys(songData).length === 8 && songData.type !== undefined && songData.mid !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.duration !== undefined && songData.skipDuration !== undefined && songData.img !== undefined) {
                     songData.likes = 0;
                     songData.dislikes = 0
 
@@ -655,6 +658,7 @@ Meteor.methods({
                                 title: songData.title,
                                 artist: songData.artist,
                                 duration: songData.duration,
+                                skipDuration: songData.skipDuration,
                                 img: songData.img,
                                 type: songData.type,
                                 likes: songData.likes,