|
@@ -371,7 +371,19 @@ Template.profile.events({
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+var seekerBarInterval = undefined;
|
|
|
+
|
|
|
Template.queues.events({
|
|
|
+ /* TODO Add undo delete button */
|
|
|
+ "input #id": function() {
|
|
|
+ console.log("Change!");
|
|
|
+ $("#previewPlayerContainer").addClass("hide-preview");
|
|
|
+ },
|
|
|
+ "input #img": function() {
|
|
|
+ var url = $("#img").val();
|
|
|
+ console.log(url);
|
|
|
+ Session.set("image_url", url);
|
|
|
+ },
|
|
|
"click .preview-button": function(e){
|
|
|
Session.set("song", this);
|
|
|
$("#previewModal").openModal();
|
|
@@ -392,85 +404,153 @@ Template.queues.events({
|
|
|
$("#dislikes").val(this.dislikes).change();
|
|
|
$("#duration").val(this.duration).change();
|
|
|
$("#skip-duration").val(this.skipDuration).change();
|
|
|
- $("#editModal").openModal();
|
|
|
+ $("#previewPlayerContainer").addClass("hide-preview");
|
|
|
+ Session.set("image_url", this.img);
|
|
|
+ Session.set("editing", true);
|
|
|
+ $("#editModal").openModal({
|
|
|
+ complete : function() {
|
|
|
+ Session.set("editing", false);
|
|
|
+ if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) {
|
|
|
+ YTPlayer.stopVideo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
"click .add-song-button": function(e){
|
|
|
var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
|
|
|
- Meteor.call("addSongToPlaylist", genre, this);
|
|
|
+ Meteor.call("addSongToPlaylist", genre, this, function(err) {
|
|
|
+ console.log(err);
|
|
|
+ if (err) {
|
|
|
+ var $toastContent = $('<span><strong>Song not added.</strong> ' + err.reason + '</span>');
|
|
|
+ Materialize.toast($toastContent, 8000);
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
"click .deny-song-button": function(e){
|
|
|
var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
|
|
|
Meteor.call("removeSongFromQueue", genre, this.mid);
|
|
|
},
|
|
|
"click #play": function() {
|
|
|
- $("#play").attr("disabled", true);
|
|
|
- $("#stop").attr("disabled", false);
|
|
|
+ $("#previewPlayerContainer").removeClass("hide-preview");
|
|
|
var song = Session.get("song");
|
|
|
var id = song.id;
|
|
|
- var type = song.type;
|
|
|
var volume = localStorage.getItem("volume") || 20;
|
|
|
-
|
|
|
- if (YTPlayer === undefined) {
|
|
|
- YTPlayer = new YT.Player("previewPlayer", {
|
|
|
- height: 540,
|
|
|
- width: 568,
|
|
|
- videoId: id,
|
|
|
- playerVars: {autoplay: 1, controls: 0, iv_load_policy: 3, showinfo: 0},
|
|
|
- events: {
|
|
|
- 'onReady': function(event) {
|
|
|
- event.target.seekTo(Number(song.skipDuration));
|
|
|
- event.target.playVideo();
|
|
|
- event.target.setVolume(volume);
|
|
|
- },
|
|
|
- 'onStateChange': function(event){
|
|
|
- if (event.data == YT.PlayerState.PAUSED) {
|
|
|
+ if (song.duration !== 0) {
|
|
|
+ $("#play").attr("disabled", true);
|
|
|
+ $("#stop").attr("disabled", false);
|
|
|
+ $("#pause").attr("disabled", false);
|
|
|
+ $("#forward").attr("disabled", false);
|
|
|
+ if (YTPlayer === undefined) {
|
|
|
+ YTPlayer = new YT.Player("previewPlayer", {
|
|
|
+ height: 540,
|
|
|
+ width: 568,
|
|
|
+ videoId: id,
|
|
|
+ playerVars: {autoplay: 1, controls: 0, iv_load_policy: 3, showinfo: 0, fs: 0},
|
|
|
+ events: {
|
|
|
+ 'onReady': function(event) {
|
|
|
+ event.target.seekTo(Number(song.skipDuration));
|
|
|
event.target.playVideo();
|
|
|
- }
|
|
|
- if (event.data == YT.PlayerState.PLAYING) {
|
|
|
- $("#play").attr("disabled", true);
|
|
|
- $("#stop").attr("disabled", false);
|
|
|
- } else {
|
|
|
- $("#play").attr("disabled", false);
|
|
|
- $("#stop").attr("disabled", true);
|
|
|
+ event.target.setVolume(volume);
|
|
|
+ var duration = Session.get("song").duration;
|
|
|
+ var d = moment.duration(parseInt(duration), 'seconds');
|
|
|
+ $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
|
|
|
+ },
|
|
|
+ 'onStateChange': function(event){
|
|
|
+ if (event.data == YT.PlayerState.PAUSED) {
|
|
|
+ if (seekerBarInterval !== undefined) {
|
|
|
+ Meteor.clearInterval(seekerBarInterval);
|
|
|
+ seekerBarInterval = undefined;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (event.data == YT.PlayerState.UNSTARTED) {
|
|
|
+ if (seekerBarInterval !== undefined) {
|
|
|
+ Meteor.clearInterval(seekerBarInterval);
|
|
|
+ seekerBarInterval = undefined;
|
|
|
+ }
|
|
|
+ $(".seeker-bar").css({width: "0"});
|
|
|
+ $("#time-elapsed").text("0:00");
|
|
|
+ $("#previewPlayerContainer").addClass("hide-preview");
|
|
|
+ }
|
|
|
+ if (event.data == YT.PlayerState.PLAYING) {
|
|
|
+ seekerBarInterval = Meteor.setInterval(function() {
|
|
|
+ var duration = Session.get("song").duration;
|
|
|
+ var timeElapsed = YTPlayer.getCurrentTime();
|
|
|
+ var skipDuration = Session.get("song").skipDuration;
|
|
|
+
|
|
|
+ if (duration <= (timeElapsed - skipDuration)) {
|
|
|
+ YTPlayer.stopVideo();
|
|
|
+ $("#play").attr("disabled", false);
|
|
|
+ $("#stop").attr("disabled", true);
|
|
|
+ $("#pause").attr("disabled", true);
|
|
|
+ $("#forward").attr("disabled", true);
|
|
|
+ $("#previewPlayerContainer").addClass("hide-preview");
|
|
|
+ $(".seeker-bar").css({width: "0"});
|
|
|
+ $("#time-elapsed").text("0:00");
|
|
|
+ Meteor.clearInterval(seekerBarInterval);
|
|
|
+ } else {
|
|
|
+ var percentComplete = (timeElapsed - skipDuration) / duration * 100;
|
|
|
+ $(".seeker-bar").css({width: percentComplete + "%"});
|
|
|
+ var d = moment.duration(timeElapsed - skipDuration, 'seconds');
|
|
|
+ $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
|
|
|
+ }
|
|
|
+ }, 100);
|
|
|
+ $("#play").attr("disabled", true);
|
|
|
+ $("#stop").attr("disabled", false);
|
|
|
+ $("#pause").attr("disabled", false);
|
|
|
+ $("#forward").attr("disabled", false);
|
|
|
+ } else {
|
|
|
+ $("#play").attr("disabled", false);
|
|
|
+ $("#stop").attr("disabled", true);
|
|
|
+ $("#pause").attr("disabled", true);
|
|
|
+ $("#forward").attr("disabled", true);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ if (YTPlayer.getPlayerState() === 2) {
|
|
|
+ YTPlayer.playVideo();
|
|
|
+ } else {
|
|
|
+ console.log(id, song.skipDuration, song.duration);
|
|
|
+ YTPlayer.loadVideoById(id);
|
|
|
+ YTPlayer.seekTo(Number(song.skipDuration));
|
|
|
}
|
|
|
- });
|
|
|
- } else {
|
|
|
- YTPlayer.loadVideoById(id);
|
|
|
- YTPlayer.seekTo(Number(song.skipDuration));
|
|
|
- }
|
|
|
- $("#previewPlayer").show();
|
|
|
-
|
|
|
- if (previewEndSongTimeout !== undefined) {
|
|
|
- Meteor.clearTimeout(previewEndSongTimeout);
|
|
|
- }
|
|
|
- previewEndSongTimeout = Meteor.setTimeout(function() {
|
|
|
- if (YTPlayer !== undefined) {
|
|
|
- YTPlayer.stopVideo();
|
|
|
}
|
|
|
- $("#play").attr("disabled", false);
|
|
|
- $("#stop").attr("disabled", true);
|
|
|
- $("#previewPlayer").hide();
|
|
|
- }, song.duration * 1000);
|
|
|
+ $("#previewPlayerContainer").removeClass("hide-preview");
|
|
|
+ }
|
|
|
},
|
|
|
"click #stop": function() {
|
|
|
$("#play").attr("disabled", false);
|
|
|
$("#stop").attr("disabled", true);
|
|
|
+ $("#pause").attr("disabled", true);
|
|
|
+ $("#forward").attr("disabled", true);
|
|
|
if (previewEndSongTimeout !== undefined) {
|
|
|
Meteor.clearTimeout(previewEndSongTimeout);
|
|
|
}
|
|
|
- if (YTPlayer !== undefined) {
|
|
|
+ if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) {
|
|
|
YTPlayer.stopVideo();
|
|
|
}
|
|
|
},
|
|
|
+ "click #pause": function() {
|
|
|
+ $("#play").attr("disabled", false);
|
|
|
+ $("#stop").attr("disabled", false);
|
|
|
+ $("#pause").attr("disabled", true);
|
|
|
+ $("#forward").attr("disabled", true);
|
|
|
+ if (previewEndSongTimeout !== undefined) {
|
|
|
+ Meteor.clearTimeout(previewEndSongTimeout);
|
|
|
+ }
|
|
|
+ if (YTPlayer !== undefined && YTPlayer.pauseVideo !== undefined) {
|
|
|
+ YTPlayer.pauseVideo();
|
|
|
+ }
|
|
|
+ },
|
|
|
"click #forward": function() {
|
|
|
var error = false;
|
|
|
if (YTPlayer !== undefined) {
|
|
|
var duration = Number(Session.get("song").duration) | 0;
|
|
|
var skipDuration = Number(Session.get("song").skipDuration) | 0;
|
|
|
if (YTPlayer.getDuration() < duration + skipDuration) {
|
|
|
- alert("The duration of the YouTube video is smaller than the duration.");
|
|
|
+ var $toastContent = $('<span><strong>Error.</strong> The song duration is longer than the length of the video.</span>');
|
|
|
+ Materialize.toast($toastContent, 8000);
|
|
|
error = true;
|
|
|
} else {
|
|
|
YTPlayer.seekTo(skipDuration + duration - 10);
|
|
@@ -486,7 +566,9 @@ Template.queues.events({
|
|
|
}
|
|
|
$("#play").attr("disabled", false);
|
|
|
$("#stop").attr("disabled", true);
|
|
|
- $("#previewPlayer").hide();
|
|
|
+ $("#pause").attr("disabled", true);
|
|
|
+ $("#forward").attr("disabled", true);
|
|
|
+ $("#previewPlayerContainer").addClass("hide-preview");
|
|
|
}, 10000);
|
|
|
}
|
|
|
},
|
|
@@ -497,8 +579,8 @@ Template.queues.events({
|
|
|
for(var i in data){
|
|
|
for(var j in data[i].items){
|
|
|
if(search.indexOf(data[i].items[j].name) !== -1 && artistName.indexOf(data[i].items[j].artists[0].name) !== -1){
|
|
|
- $("#img").val(data[i].items[j].album.images[2].url);
|
|
|
- $("#duration").val(data[i].items[j].duration_ms / 1000);
|
|
|
+ $("#img").val(data[i].items[j].album.images[2].url).change();
|
|
|
+ $("#duration").val(data[i].items[j].duration_ms / 1000).change();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
@@ -507,6 +589,7 @@ Template.queues.events({
|
|
|
},
|
|
|
"click #save-song-button": function() {
|
|
|
var newSong = {};
|
|
|
+ newSong.mid = $("#mid").val();
|
|
|
newSong.id = $("#id").val();
|
|
|
newSong.likes = Number($("#likes").val());
|
|
|
newSong.dislikes = Number($("#dislikes").val());
|
|
@@ -515,18 +598,19 @@ Template.queues.events({
|
|
|
newSong.img = $("#img").val();
|
|
|
newSong.duration = Number($("#duration").val());
|
|
|
newSong.skipDuration = $("#skip-duration").val();
|
|
|
+ newSong.requestedBy = Session.get("song").requestedBy;
|
|
|
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');
|
|
|
- });
|
|
|
- } else {
|
|
|
- Meteor.call("updateQueueSong", Session.get("genre"), Session.get("song"), newSong, function() {
|
|
|
- $('#editModal').modal('hide');
|
|
|
- });
|
|
|
- }
|
|
|
+ Meteor.call("updateQueueSong", Session.get("genre"), Session.get("song"), newSong, function(err, res) {
|
|
|
+ console.log(err, res);
|
|
|
+ if (err) {
|
|
|
+ var $toastContent = $('<span><strong>Song not saved.</strong> ' + err.reason + '</span>');
|
|
|
+ Materialize.toast($toastContent, 8000);
|
|
|
+ } else {
|
|
|
+ Session.set("song", newSong);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -1345,6 +1429,8 @@ Template.settings.events({
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+var previewEndSongTimeout = undefined;
|
|
|
+
|
|
|
Template.stations.events({
|
|
|
"click .preview-button": function(e){
|
|
|
Session.set("song", this);
|
|
@@ -1465,10 +1551,11 @@ Template.stations.events({
|
|
|
"click #stop": function() {
|
|
|
$("#play").attr("disabled", false);
|
|
|
$("#stop").attr("disabled", true);
|
|
|
+ $("#pause").attr("disabled", true);
|
|
|
if (previewEndSongTimeout !== undefined) {
|
|
|
Meteor.clearTimeout(previewEndSongTimeout);
|
|
|
}
|
|
|
- if (YTPlayer !== undefined) {
|
|
|
+ if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) {
|
|
|
YTPlayer.stopVideo();
|
|
|
}
|
|
|
},
|