Closed rochapablo closed 8 years ago
Well, never mind!
Here's what I did:
$rootScope.$on('music:isPlaying', function(event, data) {
var currentTrackKey = angularPlayer.getIndexByValue(soundManager.soundIDs, angularPlayer.getCurrentTrack());
var nextTrackKey =+ currentTrackKey + 1;
var nextTrack = soundManager.soundIDs[nextTrackKey];
if(data === false && typeof nextTrack === 'undefined') {
angularPlayer.initPlayTrack(soundManager.soundIDs[0], true);
}
});
As solution I suggest:
$scope.play = function (genre) {
$timeout(function () {
angularPlayer.stop();
angularPlayer.setCurrentTrack(null);
angularPlayer.clearPlaylist(function () {
if (genre !== undefined) {
$scope.filtered = filterFilter($scope.songs, {'genre': genre});
} else {
$scope.filtered = $scope.songs;
}
if (random) {
$scope.filtered = $filter('shuffleArray')($scope.filtered);
}
if ($scope.filtered.length == 0) {
console.log("No songs by genre " + genre);
}
angular.forEach($scope.filtered, function (value) {
angularPlayer.addTrack(value);
});
angularPlayer.play();
});
});
};
Hey @oliwin,
I tried fix the loop and it's seems that now it's working.
You can check the code bellow or the example running.
app.controller('BaseCtrl', ['$rootScope', '$timeout', 'angularPlayer', function($root, $timeout, player) {
var $ctrl = this;
$ctrl.songs = dbsongs();
// here, i'm also following the pattern of the library
var nextTrack = function() {
var current = player.getIndexByValue(soundManager.soundIDs, player.getCurrentTrack());
var index = +current + 1;
return soundManager.soundIDs[index];
}
$root.$on('track:progress', function(event, data) {
// at the end of the track 100% will be given
if (data < 100) {
return;
}
// undefined means... well nothing more to play
if (typeof nextTrack() !== 'undefined') {
return;
}
// not sure yet, but... sometimes an error will apper ".length undefined"
// $timeout(function() {
// here, i'm just follow the pattern of the angular-soundmanager2.js
player.clearPlaylist(function(data) {
player.setCurrentTrack(null);
player.stop();
// as the playlist was cleaned, we need to add all over again
for (var i = 0; i < $ctrl.songs.length; i++) {
player.addTrack($ctrl.songs[i]);
}
player.play();
});
// }, 1001);
});
}]);
Hope that now we had kill these dragon.
Peace man!
Hi, man! It is great, but I can not see play() method, how to start playing?
2017-02-10 2:01 GMT+04:00 Pablo notifications@github.com:
Hey @oliwin https://github.com/oliwin,
I tried fix the loop and it's seems that now it's working.
You can check the code bellow or the example running http://codepen.io/rochapablo/pen/jyedeE?editors=0011.
app.controller('BaseCtrl', ['$rootScope', '$timeout', 'angularPlayer', function($root, $timeout, player) {
var $ctrl = this;
$ctrl.songs = dbsongs();
// here, i'm also following the pattern of the library var nextTrack = function() { var current = player.getIndexByValue(soundManager.soundIDs, player.getCurrentTrack()); var index = +current + 1; return soundManager.soundIDs[index]; }
$root.$on('track:progress', function(event, data) {
// at the end of the track 100% will be given if (data < 100) { return; } // undefined means... well nothing more to play if (typeof nextTrack() !== 'undefined') { return; } // not sure yet, but... sometimes an error will apper ".length undefined" // $timeout(function() { // here, i'm just follow the pattern of the angular-soundmanager2.js player.clearPlaylist(function(data) { player.setCurrentTrack(null); player.stop(); // as the playlist was cleaned, we need to add all over again for (var i = 0; i < $ctrl.songs.length; i++) { player.addTrack($ctrl.songs[i]); } player.play(); }); // }, 1001);
});
}]);
Hope that now we had kill these dragon.
Peace man!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/perminder-klair/angular-soundmanager2/issues/45#issuecomment-278788425, or mute the thread https://github.com/notifications/unsubscribe-auth/AE4BpoZ309N23dBuvLsqqa7UszkHhsglks5ra4zOgaJpZM4HyDmF .
-- Олег Валерьевич Телефон: +(994) 51 40 333 90
@oliwin,
The play() was a method that I was using in another way, you can keep using, but you'll have to implement that.
The main problem was showing the current name, which we change frommusic:isPlaying
to `'track:progress'
plus some code inside.
I'm playing all the songs using the play-all
directive.
I don't know if you read, but for me this link had helped me a lot.
Good luck
I'm adding the songs to player like this:
But at the end, after all played how to restart the playlist and keep it in loop?