i have a song plugin html5 jquery music player which take song names from the data base. i instantiated it inside the Template.onRendered as it is recommended. and its is working but its not reactive. so if i add new songs it will not appeared inside the play list.
the template code:
< ! - - items here appears reactively {{#each allsongs}} {{songurl}} {{/each}} - - > < ! - - playlist of player plugin is not reactive - - > < div class="music-player-list">
the on created section
Template.mysongs.onCreated(function(){
this.subscribe(“songs”);
});
the on rendered section
Template.mysongs.onRendered(function(){
$(’.music-player-list’).ttwMusicPlayer(Session.get(“myPlaylist”), {
currencySymbol:’$’,
buyText:‘BUY’,
tracksToShow:3,
autoplay:false,
ratingCallback:function(index, playlistItem, rating){
//some logic to process the rating, perhaps through an ajax call
}
});
the template helper
Template.mysongs.Helpers(
allsongs : function(){
var mysongs = songs.find({}).fetch();
mysongs.forEach(function(song){
myPlaylist.push({“id”:song._id,
“title” : song.songname ,
“cover”:‘1.jpg’ ,
“duration” : song.duration,
“rating”:5,
“mp3”: song.songurl,
“buy”:’#’,
“artist”:‘Alexandra’});
console.log(song._id + " " +song.songname + " " + song.songurl);
});
Session.set(“myPlaylist”, myPlaylist);
console.log(“myPlaylist session”+Session.get(“myPlaylist”)); //reactively
return Session.get(“myPlaylist”);
});
the template events
Template.mysongs.events({
‘click: .uploadbutton’ : function(){
// get the song object
//save into database
});