mirror of
https://github.com/IrosTheBeggar/mStream.git
synced 2025-10-27 07:31:02 +00:00
Working ratings
This commit is contained in:
parent
d8cea39e4d
commit
d333036e42
@ -360,7 +360,7 @@ exports.setup = function (mstream, program) {
|
||||
"year": row.year ? row.year : '',
|
||||
"album-art": row.albumArtFilename ? row.albumArtFilename : '',
|
||||
"filename": fe.basename(row.filepath),
|
||||
"rating": row.rating ? result.rating : false
|
||||
"rating": row.rating ? row.rating : false
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@
|
||||
}
|
||||
|
||||
.songDropdown{
|
||||
min-width: 28px !important;
|
||||
min-width: 38px !important;
|
||||
height: 14px;
|
||||
background-color: #B5B5B5;
|
||||
float: right;
|
||||
@ -130,6 +130,8 @@
|
||||
font-size: 12px;
|
||||
font-family: "Arial Black", Gadget, sans-serif;
|
||||
border-bottom-left-radius: 3px;
|
||||
padding-left: 3px;
|
||||
padding-right: 3px;
|
||||
}
|
||||
|
||||
.removeSong{
|
||||
|
||||
@ -114,7 +114,6 @@ var MSTREAMAPI = (function () {
|
||||
|
||||
|
||||
mstreamModule.lookupMetadata = function (filepath, callback) {
|
||||
console.log(filepath)
|
||||
makePOSTRequest("/db/metadata", { filepath: filepath }, callback);
|
||||
}
|
||||
|
||||
@ -172,7 +171,7 @@ var MSTREAMAPI = (function () {
|
||||
}
|
||||
|
||||
if (response.metadata) {
|
||||
newSong.metadata = Object.create(response.metadata);
|
||||
newSong.metadata = response.metadata;
|
||||
MSTREAMPLAYER.resetCurrentMetadata();
|
||||
}
|
||||
});
|
||||
|
||||
@ -2,25 +2,31 @@ var MSTREAMPLAYER = (function () {
|
||||
let mstreamModule = {};
|
||||
|
||||
// Playlist variables
|
||||
mstreamModule.positionCache = {val:-1};
|
||||
mstreamModule.positionCache = { val: -1 };
|
||||
// var currentSong;
|
||||
mstreamModule.playlist = [];
|
||||
|
||||
mstreamModule.changeVolume = function(newVolume){
|
||||
if(newVolume < 0 || newVolume > 100 ){
|
||||
mstreamModule.editSongMetadata = function (key, value, songIndex) {
|
||||
mstreamModule.playlist[songIndex].metadata[key] = value;
|
||||
|
||||
// TODO: update all other playlist items with the same filepath
|
||||
}
|
||||
|
||||
mstreamModule.changeVolume = function (newVolume) {
|
||||
if (newVolume < 0 || newVolume > 100) {
|
||||
return;
|
||||
}
|
||||
mstreamModule.playerStats.volume = newVolume;
|
||||
|
||||
AV.Player.volume = newVolume;
|
||||
Howler.volume(newVolume/100)
|
||||
Howler.volume(newVolume / 100)
|
||||
}
|
||||
|
||||
// Scrobble function
|
||||
// This is a placeholder function that the API layer can take hgold of to implmenmt the scrobble call
|
||||
// This
|
||||
var scrobbleTimer;
|
||||
mstreamModule.scrobble = function(){
|
||||
mstreamModule.scrobble = function () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -31,13 +37,13 @@ var MSTREAMPLAYER = (function () {
|
||||
// }
|
||||
|
||||
|
||||
mstreamModule.addSong = function(audioData){
|
||||
if(!audioData.url || audioData.url == false){
|
||||
mstreamModule.addSong = function (audioData) {
|
||||
if (!audioData.url || audioData.url == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Handle shuffle
|
||||
if(mstreamModule.playerStats.shuffle === true){
|
||||
if (mstreamModule.playerStats.shuffle === true) {
|
||||
var pos = Math.floor(Math.random() * (shuffleCache.length + 1));
|
||||
shuffleCache.splice(pos, 0, audioData);
|
||||
}
|
||||
@ -45,61 +51,61 @@ var MSTREAMPLAYER = (function () {
|
||||
return addSongToPlaylist(audioData);
|
||||
}
|
||||
|
||||
function addSongToPlaylist(song){
|
||||
function addSongToPlaylist(song) {
|
||||
mstreamModule.playlist.push(song);
|
||||
|
||||
// If this the first song in the list
|
||||
if(mstreamModule.playlist.length === 1){
|
||||
if (mstreamModule.playlist.length === 1) {
|
||||
mstreamModule.positionCache.val = 0;
|
||||
return goToSong(mstreamModule.positionCache.val);
|
||||
}
|
||||
|
||||
// TODO: Check if we are at the end of the playlist and nothing is playing.
|
||||
// Start playing if this condition is met
|
||||
// Start playing if this condition is met
|
||||
|
||||
// Cache song if appropriate
|
||||
var oPlayer = getOtherPlayer();
|
||||
if(oPlayer.playerObject === false && mstreamModule.playlist[mstreamModule.positionCache.val + 1]){
|
||||
if (oPlayer.playerObject === false && mstreamModule.playlist[mstreamModule.positionCache.val + 1]) {
|
||||
clearTimeout(cacheTimer);
|
||||
cacheTimer = setTimeout(function(){ setCachedSong(mstreamModule.positionCache.val + 1) } , 33000);
|
||||
cacheTimer = setTimeout(function () { setCachedSong(mstreamModule.positionCache.val + 1) }, 33000);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
mstreamModule.clearAndPlay = function(song){
|
||||
mstreamModule.clearAndPlay = function (song) {
|
||||
// Clear playlist
|
||||
mstreamModule.playlist = [];
|
||||
return addSong(song);
|
||||
}
|
||||
|
||||
mstreamModule.clearPlaylist = function(){
|
||||
while(mstreamModule.playlist.length > 0) {mstreamModule.playlist.pop();}
|
||||
mstreamModule.clearPlaylist = function () {
|
||||
while (mstreamModule.playlist.length > 0) { mstreamModule.playlist.pop(); }
|
||||
mstreamModule.positionCache.val = -1;
|
||||
|
||||
clearEnd();
|
||||
|
||||
// Clear shuffle as well
|
||||
if(mstreamModule.playerStats.shuffle === true){
|
||||
if (mstreamModule.playerStats.shuffle === true) {
|
||||
// Clear Shuffle Cache
|
||||
while(shuffleCache.length > 0) {shuffleCache.pop();}
|
||||
while (shuffleCache.length > 0) { shuffleCache.pop(); }
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
mstreamModule.nextSong = function(){
|
||||
mstreamModule.nextSong = function () {
|
||||
// Stop the current song
|
||||
return goToNextSong();
|
||||
}
|
||||
mstreamModule.previousSong = function(){
|
||||
mstreamModule.previousSong = function () {
|
||||
return goToPreviousSong();
|
||||
}
|
||||
|
||||
|
||||
mstreamModule.goToSongAtPosition = function(position){
|
||||
if(!mstreamModule.playlist[position]){
|
||||
mstreamModule.goToSongAtPosition = function (position) {
|
||||
if (!mstreamModule.playlist[position]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -110,13 +116,13 @@ var MSTREAMPLAYER = (function () {
|
||||
}
|
||||
|
||||
// TODO: Log Failures
|
||||
mstreamModule.removeSongAtPosition = function(position, sanityCheckUrl){
|
||||
mstreamModule.removeSongAtPosition = function (position, sanityCheckUrl) {
|
||||
// Check that position is filled
|
||||
if (position > mstreamModule.playlist.length || position < 0) {
|
||||
return false;
|
||||
}
|
||||
// If sanityCheckUrl, check that url are the same
|
||||
if(sanityCheckUrl && sanityCheckUrl != mstreamModule.playlist[position].url){
|
||||
if (sanityCheckUrl && sanityCheckUrl != mstreamModule.playlist[position].url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -126,17 +132,17 @@ var MSTREAMPLAYER = (function () {
|
||||
mstreamModule.playlist.splice(position, 1);
|
||||
|
||||
|
||||
if(mstreamModule.playerStats.shuffle === true){
|
||||
if (mstreamModule.playerStats.shuffle === true) {
|
||||
// Remove song from shuffle Cache
|
||||
for(var i=0, len=shuffleCache.length; i < len; i++){
|
||||
for (var i = 0, len = shuffleCache.length; i < len; i++) {
|
||||
// Check if this is the current song
|
||||
if(removedSong === shuffleCache[i]){
|
||||
if (removedSong === shuffleCache[i]) {
|
||||
shuffleCache.splice(i, 1);
|
||||
}
|
||||
}
|
||||
for(var i=0, len=shufflePrevious.length; i < len; i++){
|
||||
for (var i = 0, len = shufflePrevious.length; i < len; i++) {
|
||||
// Check if this is the current song
|
||||
if(removedSong === shufflePrevious[i]){
|
||||
if (removedSong === shufflePrevious[i]) {
|
||||
shufflePrevious.splice(i, 1);
|
||||
}
|
||||
}
|
||||
@ -144,48 +150,48 @@ var MSTREAMPLAYER = (function () {
|
||||
}
|
||||
|
||||
// Handle case where user removes current song and it's the last song in the playlist
|
||||
if(position === mstreamModule.positionCache.val && position === mstreamModule.playlist.length ){
|
||||
if (position === mstreamModule.positionCache.val && position === mstreamModule.playlist.length) {
|
||||
clearEnd();
|
||||
// Go to random song if random is set
|
||||
if(mstreamModule.playerStats.shuffle === true){
|
||||
if (mstreamModule.playerStats.shuffle === true) {
|
||||
goToNextSong();
|
||||
}else if(mstreamModule.playerStats.shouldLoop === true){ // Loop is loop is set
|
||||
} else if (mstreamModule.playerStats.shouldLoop === true) { // Loop is loop is set
|
||||
mstreamModule.positionCache.val = 0;
|
||||
goToSong(mstreamModule.positionCache.val);
|
||||
}else{ // Reset to start is nothing is set
|
||||
} else { // Reset to start is nothing is set
|
||||
mstreamModule.positionCache.val = -1;
|
||||
}
|
||||
}else if(position === mstreamModule.positionCache.val){ // User removes currently playing song
|
||||
} else if (position === mstreamModule.positionCache.val) { // User removes currently playing song
|
||||
// Go to next song
|
||||
clearEnd();
|
||||
|
||||
// If random is set, go to random song
|
||||
if(mstreamModule.playerStats.shuffle === true){
|
||||
if (mstreamModule.playerStats.shuffle === true) {
|
||||
goToNextSong();
|
||||
}else{
|
||||
} else {
|
||||
goToSong(mstreamModule.positionCache.val);
|
||||
}
|
||||
|
||||
}else if( position < mstreamModule.positionCache.val){
|
||||
} else if (position < mstreamModule.positionCache.val) {
|
||||
// Lower positioncache by 1 if necessary
|
||||
mstreamModule.positionCache.val--;
|
||||
}else if( position === (mstreamModule.positionCache.val + 1) ){
|
||||
} else if (position === (mstreamModule.positionCache.val + 1)) {
|
||||
// setCachedSong(mstreamModule.positionCache.val + 1);
|
||||
clearTimeout(cacheTimer);
|
||||
cacheTimer = setTimeout(function(){ setCachedSong(mstreamModule.positionCache.val + 1) } , 33000);
|
||||
cacheTimer = setTimeout(function () { setCachedSong(mstreamModule.positionCache.val + 1) }, 33000);
|
||||
}
|
||||
}
|
||||
|
||||
mstreamModule.getCurrentSong = function(){
|
||||
mstreamModule.getCurrentSong = function () {
|
||||
var lPlayer = getCurrentPlayer();
|
||||
return lPlayer.songObject;
|
||||
}
|
||||
|
||||
function goToPreviousSong(){
|
||||
function goToPreviousSong() {
|
||||
// TODO: If random is set, go to previous song from cache
|
||||
if(mstreamModule.playerStats.shuffle === true){
|
||||
if (mstreamModule.playerStats.shuffle === true) {
|
||||
// TODO: Check that there is a previous song to go back to
|
||||
if(shufflePrevious.length <= 1){
|
||||
if (shufflePrevious.length <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -193,23 +199,23 @@ var MSTREAMPLAYER = (function () {
|
||||
var nextSong = shufflePrevious.pop();
|
||||
shuffleCache.push(nextSong);
|
||||
|
||||
var currentSong = shufflePrevious[shufflePrevious.length-1];
|
||||
var currentSong = shufflePrevious[shufflePrevious.length - 1];
|
||||
|
||||
// Reset position cache
|
||||
for(var i=0, len=mstreamModule.playlist.length; i < len; i++){
|
||||
for (var i = 0, len = mstreamModule.playlist.length; i < len; i++) {
|
||||
// Check if this is the current song
|
||||
if(currentSong === mstreamModule.playlist[i]){
|
||||
if (currentSong === mstreamModule.playlist[i]) {
|
||||
mstreamModule.positionCache.val = i;
|
||||
}
|
||||
}
|
||||
clearEnd();
|
||||
|
||||
goToSong(mstreamModule.positionCache.val );
|
||||
goToSong(mstreamModule.positionCache.val);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure there is a previous song
|
||||
if(mstreamModule.positionCache.val === 0 || mstreamModule.positionCache.val === -1){
|
||||
if (mstreamModule.positionCache.val === 0 || mstreamModule.positionCache.val === -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -219,39 +225,39 @@ var MSTREAMPLAYER = (function () {
|
||||
return goToSong(mstreamModule.positionCache.val);
|
||||
}
|
||||
|
||||
function goToNextSong(){
|
||||
function goToNextSong() {
|
||||
// If random is set, go to random song
|
||||
if(mstreamModule.playerStats.shuffle === true){
|
||||
if (mstreamModule.playerStats.shuffle === true) {
|
||||
// Chose a random value
|
||||
var nextSong = shuffleCache.pop();
|
||||
|
||||
// Prevent same song from playing twice after a re-shuffle
|
||||
if(nextSong === mstreamModule.getCurrentSong()){
|
||||
if (nextSong === mstreamModule.getCurrentSong()) {
|
||||
console.log('DUPEEEEE');
|
||||
shuffleCache.unshift(nextSong);
|
||||
nextSong = shuffleCache.pop();
|
||||
}
|
||||
|
||||
if(shuffleCache.length === 0){
|
||||
if (shuffleCache.length === 0) {
|
||||
newShuffle();
|
||||
}
|
||||
|
||||
|
||||
// Reset position cache
|
||||
for(var i=0, len=mstreamModule.playlist.length; i < len; i++){
|
||||
for (var i = 0, len = mstreamModule.playlist.length; i < len; i++) {
|
||||
// Check if this is the current song
|
||||
if(nextSong === mstreamModule.playlist[i]){
|
||||
if (nextSong === mstreamModule.playlist[i]) {
|
||||
mstreamModule.positionCache.val = i;
|
||||
}
|
||||
}
|
||||
clearEnd();
|
||||
|
||||
goToSong(mstreamModule.positionCache.val );
|
||||
goToSong(mstreamModule.positionCache.val);
|
||||
|
||||
// Remove duplicates from shuffle previous
|
||||
for(var i=0, len=shufflePrevious.length; i < len; i++){
|
||||
for (var i = 0, len = shufflePrevious.length; i < len; i++) {
|
||||
// Check if this is the current song
|
||||
if(nextSong === shufflePrevious[i]){
|
||||
if (nextSong === shufflePrevious[i]) {
|
||||
shufflePrevious.splice(i, 1);
|
||||
}
|
||||
}
|
||||
@ -263,10 +269,10 @@ var MSTREAMPLAYER = (function () {
|
||||
}
|
||||
|
||||
// Check if the next song exists
|
||||
if(!mstreamModule.playlist[mstreamModule.positionCache.val + 1]){
|
||||
if (!mstreamModule.playlist[mstreamModule.positionCache.val + 1]) {
|
||||
|
||||
// If loop is set and no other song, go back to first song
|
||||
if(mstreamModule.playerStats.shouldLoop === true && mstreamModule.playlist.length > 0){
|
||||
if (mstreamModule.playerStats.shouldLoop === true && mstreamModule.playlist.length > 0) {
|
||||
mstreamModule.positionCache.val = 0;
|
||||
clearEnd();
|
||||
|
||||
@ -284,30 +290,30 @@ var MSTREAMPLAYER = (function () {
|
||||
}
|
||||
|
||||
|
||||
function getCurrentPlayer(){
|
||||
if(curP === 'A'){
|
||||
function getCurrentPlayer() {
|
||||
if (curP === 'A') {
|
||||
return playerA;
|
||||
}else if(curP === 'B'){
|
||||
} else if (curP === 'B') {
|
||||
return playerB;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getOtherPlayer(){
|
||||
if(curP === 'A'){
|
||||
function getOtherPlayer() {
|
||||
if (curP === 'A') {
|
||||
return playerB;
|
||||
}else if(curP === 'B'){
|
||||
} else if (curP === 'B') {
|
||||
return playerA;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function flipFlop(){
|
||||
if(curP === 'A'){
|
||||
function flipFlop() {
|
||||
if (curP === 'A') {
|
||||
curP = 'B';
|
||||
}else if(curP === 'B'){
|
||||
} else if (curP === 'B') {
|
||||
curP = 'A';
|
||||
}
|
||||
|
||||
@ -315,8 +321,8 @@ var MSTREAMPLAYER = (function () {
|
||||
}
|
||||
|
||||
|
||||
function goToSong(position){
|
||||
if(!mstreamModule.playlist[position]){
|
||||
function goToSong(position) {
|
||||
if (!mstreamModule.playlist[position]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -324,9 +330,9 @@ var MSTREAMPLAYER = (function () {
|
||||
var otherPlayerObject = getOtherPlayer();
|
||||
|
||||
// Stop the current song
|
||||
if(localPlayerObject.playerType === 'aurora' ){
|
||||
if (localPlayerObject.playerType === 'aurora') {
|
||||
localPlayerObject.playerObject.stop();
|
||||
}else if(localPlayerObject.playerType === 'howler'){
|
||||
} else if (localPlayerObject.playerType === 'howler') {
|
||||
localPlayerObject.playerObject.unload();
|
||||
}
|
||||
|
||||
@ -337,22 +343,22 @@ var MSTREAMPLAYER = (function () {
|
||||
// TODO: Handle situation where next song is same as current song
|
||||
|
||||
// Song is cached
|
||||
if(otherPlayerObject.songObject === mstreamModule.playlist[position]){
|
||||
if (otherPlayerObject.songObject === mstreamModule.playlist[position]) {
|
||||
// console.log('USING CACHED SONG');
|
||||
flipFlop();
|
||||
// Play
|
||||
mstreamModule.playPause();
|
||||
|
||||
}else{
|
||||
} else {
|
||||
// console.log('DID NOT USE CACHE');
|
||||
setMedia(mstreamModule.playlist[position], localPlayerObject, true);
|
||||
}
|
||||
|
||||
var lPlayer = getCurrentPlayer();
|
||||
var lPlayer = getCurrentPlayer();
|
||||
var curSong = lPlayer.songObject;
|
||||
// TODO: Handle instace where metadata is empty
|
||||
// mstreamModule.playerStats.metadata = curSong.metadata;
|
||||
if(curSong.metadata){
|
||||
if (curSong.metadata) {
|
||||
mstreamModule.resetCurrentMetadata();
|
||||
}
|
||||
|
||||
@ -360,27 +366,27 @@ var MSTREAMPLAYER = (function () {
|
||||
// TODO: This is a mess, figure out a better way
|
||||
var newOtherPlayerObject = getOtherPlayer();
|
||||
newOtherPlayerObject.playerType = false;
|
||||
newOtherPlayerObject.playerObject = false;
|
||||
newOtherPlayerObject.songObject= false;
|
||||
newOtherPlayerObject.playerObject = false;
|
||||
newOtherPlayerObject.songObject = false;
|
||||
|
||||
// Cache next song
|
||||
// The timer prevents excessive cachign when the user starts button mashing
|
||||
clearTimeout(cacheTimer);
|
||||
cacheTimer = setTimeout(function(){ setCachedSong(position + 1) } , 33000);
|
||||
cacheTimer = setTimeout(function () { setCachedSong(position + 1) }, 33000);
|
||||
|
||||
// Scrobble song after 30 seconds
|
||||
clearTimeout(scrobbleTimer);
|
||||
scrobbleTimer = setTimeout(function(){ mstreamModule.scrobble() } , 30000);
|
||||
scrobbleTimer = setTimeout(function () { mstreamModule.scrobble() }, 30000);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
mstreamModule.resetCurrentMetadata = function() {
|
||||
var lPlayer = getCurrentPlayer();
|
||||
mstreamModule.resetCurrentMetadata = function () {
|
||||
var lPlayer = getCurrentPlayer();
|
||||
var curSong = lPlayer.songObject;
|
||||
// TODO: Handle instace where metadata is empty
|
||||
// mstreamModule.playerStats.metadata = curSong.metadata;
|
||||
if(curSong.metadata){
|
||||
if (curSong.metadata) {
|
||||
mstreamModule.playerStats.metadata.artist = curSong.metadata.artist;
|
||||
mstreamModule.playerStats.metadata.album = curSong.metadata.album;
|
||||
mstreamModule.playerStats.metadata.track = curSong.metadata.track;
|
||||
@ -392,15 +398,15 @@ var MSTREAMPLAYER = (function () {
|
||||
}
|
||||
|
||||
|
||||
mstreamModule.resetPositionCache = function(){
|
||||
mstreamModule.resetPositionCache = function () {
|
||||
var len;
|
||||
|
||||
var lPlayer = getCurrentPlayer();
|
||||
var lPlayer = getCurrentPlayer();
|
||||
var curSong = lPlayer.songObject;
|
||||
|
||||
for(var i=0, len=mstreamModule.playlist.length; i < len; i++){
|
||||
for (var i = 0, len = mstreamModule.playlist.length; i < len; i++) {
|
||||
// Check if this is the current song
|
||||
if(curSong === mstreamModule.playlist[i]){
|
||||
if (curSong === mstreamModule.playlist[i]) {
|
||||
mstreamModule.positionCache.val = i;
|
||||
return;
|
||||
}
|
||||
@ -414,31 +420,31 @@ var MSTREAMPLAYER = (function () {
|
||||
|
||||
// ========================= Aurora Player ===============
|
||||
// Shell for interacting with Aurora
|
||||
function AVPlayerPlay(){
|
||||
function AVPlayerPlay() {
|
||||
var localPlayer = getCurrentPlayer();
|
||||
|
||||
if(localPlayer.playerObject.playing){
|
||||
if (localPlayer.playerObject.playing) {
|
||||
return;
|
||||
}
|
||||
localPlayer.playerObject.play();
|
||||
mstreamModule.playerStats.playing = true;
|
||||
|
||||
}
|
||||
function AVPlayerPause(){
|
||||
function AVPlayerPause() {
|
||||
var localPlayer = getCurrentPlayer();
|
||||
|
||||
localPlayer.playerObject.pause();
|
||||
mstreamModule.playerStats.playing = false;
|
||||
|
||||
}
|
||||
function AVPlayerPlayPause(){
|
||||
function AVPlayerPlayPause() {
|
||||
var localPlayer = getCurrentPlayer();
|
||||
|
||||
// TODO: Check that media is loaded
|
||||
if(localPlayer.playerObject.playing){
|
||||
if (localPlayer.playerObject.playing) {
|
||||
localPlayer.playerObject.pause();
|
||||
mstreamModule.playerStats.playing = false;
|
||||
}else{
|
||||
} else {
|
||||
localPlayer.playerObject.play();
|
||||
mstreamModule.playerStats.playing = true;
|
||||
}
|
||||
@ -450,26 +456,26 @@ var MSTREAMPLAYER = (function () {
|
||||
|
||||
|
||||
// ========================= Howler Player ===============
|
||||
function howlPlayerPlay(){
|
||||
function howlPlayerPlay() {
|
||||
var localPlayer = getCurrentPlayer();
|
||||
mstreamModule.playerStats.playing = true;
|
||||
|
||||
localPlayer.playerObject.play();
|
||||
}
|
||||
function howlPlayerPause(){
|
||||
function howlPlayerPause() {
|
||||
var localPlayer = getCurrentPlayer();
|
||||
mstreamModule.playerStats.playing = false;
|
||||
|
||||
localPlayer.playerObject.pause();
|
||||
}
|
||||
function howlPlayerPlayPause(){
|
||||
function howlPlayerPlayPause() {
|
||||
var localPlayer = getCurrentPlayer();
|
||||
|
||||
// TODO: Check that media is loaded
|
||||
if(localPlayer.playerObject.playing()){
|
||||
if (localPlayer.playerObject.playing()) {
|
||||
mstreamModule.playerStats.playing = false;
|
||||
localPlayer.playerObject.pause();
|
||||
}else{
|
||||
} else {
|
||||
localPlayer.playerObject.play();
|
||||
mstreamModule.playerStats.playing = true;
|
||||
|
||||
@ -485,14 +491,14 @@ var MSTREAMPLAYER = (function () {
|
||||
// ========================================================
|
||||
|
||||
|
||||
function clearEnd(){
|
||||
function clearEnd() {
|
||||
var localPlayer = getCurrentPlayer();
|
||||
|
||||
if(localPlayer.playerType === 'aurora' ){
|
||||
localPlayer.playerObject.on("end", function() {
|
||||
if (localPlayer.playerType === 'aurora') {
|
||||
localPlayer.playerObject.on("end", function () {
|
||||
return
|
||||
}, false);
|
||||
}else if(localPlayer.playerType === 'howler'){
|
||||
} else if (localPlayer.playerType === 'howler') {
|
||||
localPlayer.playerObject.off('end');
|
||||
}
|
||||
}
|
||||
@ -500,23 +506,23 @@ var MSTREAMPLAYER = (function () {
|
||||
|
||||
|
||||
// Player
|
||||
// Event: On Song end
|
||||
// Set Media
|
||||
// Play, pause, skip, etc
|
||||
mstreamModule.playPause = function(){
|
||||
// Event: On Song end
|
||||
// Set Media
|
||||
// Play, pause, skip, etc
|
||||
mstreamModule.playPause = function () {
|
||||
var localPlayer = getCurrentPlayer();
|
||||
|
||||
if(localPlayer.playerType === 'aurora' ){
|
||||
if (localPlayer.playerType === 'aurora') {
|
||||
return AVPlayerPlayPause();
|
||||
}else if(localPlayer.playerType === 'howler'){
|
||||
} else if (localPlayer.playerType === 'howler') {
|
||||
return howlPlayerPlayPause();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mstreamModule.playerStats = {
|
||||
duration:0,
|
||||
currentTime:0,
|
||||
duration: 0,
|
||||
currentTime: 0,
|
||||
playing: false,
|
||||
repeat: false,
|
||||
shuffle: false,
|
||||
@ -545,51 +551,51 @@ var MSTREAMPLAYER = (function () {
|
||||
|
||||
var curP = 'A';
|
||||
|
||||
function setMedia(song, player, play){
|
||||
function setMedia(song, player, play) {
|
||||
|
||||
if(song.url.indexOf('.flac') !== -1 && Howler.codecs('flac') === false ){
|
||||
if (song.url.indexOf('.flac') !== -1 && Howler.codecs('flac') === false) {
|
||||
// Set via aurora
|
||||
player.playerType = 'aurora';
|
||||
|
||||
player.playerObject = AV.Player.fromURL(song.url);
|
||||
player.playerObject.on("end", function() {
|
||||
player.playerObject.on("end", function () {
|
||||
callMeOnStreamEnd();
|
||||
}, false);
|
||||
// Handle error event
|
||||
player.playerObject.on("error", function(e) {
|
||||
player.playerObject.on("error", function (e) {
|
||||
// TODO: GO TO NEXT SONG
|
||||
}, false);
|
||||
player.playerObject.on("metadata", function() {
|
||||
player.playerObject.on("metadata", function () {
|
||||
// Move this to metadata ???
|
||||
if(play == true){
|
||||
if (play == true) {
|
||||
AVPlayerPlay();
|
||||
}
|
||||
}, false);
|
||||
|
||||
player.playerObject.preload();
|
||||
|
||||
}else{
|
||||
} else {
|
||||
player.playerType = 'howler';
|
||||
|
||||
player.playerObject = new Howl({
|
||||
src: [song.url],
|
||||
html5: true, // Force to HTML5. Otherwise streaming will suck
|
||||
// onplay: function() { },
|
||||
onload: function() {
|
||||
onload: function () {
|
||||
|
||||
},
|
||||
onend: function() {
|
||||
onend: function () {
|
||||
callMeOnStreamEnd();
|
||||
},
|
||||
onpause: function() {
|
||||
onpause: function () {
|
||||
},
|
||||
onstop: function() {
|
||||
onstop: function () {
|
||||
},
|
||||
onplay: function(){
|
||||
onplay: function () {
|
||||
}
|
||||
});
|
||||
|
||||
if(play == true){
|
||||
if (play == true) {
|
||||
howlPlayerPlay();
|
||||
}
|
||||
}
|
||||
@ -599,8 +605,8 @@ var MSTREAMPLAYER = (function () {
|
||||
|
||||
|
||||
|
||||
function callMeOnStreamEnd(){
|
||||
mstreamModule.playerStats.playing= false;
|
||||
function callMeOnStreamEnd() {
|
||||
mstreamModule.playerStats.playing = false;
|
||||
|
||||
// Go to next song
|
||||
goToNextSong();
|
||||
@ -610,38 +616,38 @@ var MSTREAMPLAYER = (function () {
|
||||
|
||||
|
||||
|
||||
// NOTE: Seektime is in seconds
|
||||
mstreamModule.seek = function(seekTime){
|
||||
var lPlayer = getCurrentPlayer();
|
||||
if(lPlayer.playerType === 'aurora' ){
|
||||
// Do nothing, auroradoesn't support seeking right now
|
||||
return false;
|
||||
}else if(lPlayer.playerType === 'howler'){
|
||||
// Check that the seek number is less than the duration
|
||||
if(seekTime < 0 || seekTime > lPlayer.playerObject._duration){
|
||||
// NOTE: Seektime is in seconds
|
||||
mstreamModule.seek = function (seekTime) {
|
||||
var lPlayer = getCurrentPlayer();
|
||||
if (lPlayer.playerType === 'aurora') {
|
||||
// Do nothing, auroradoesn't support seeking right now
|
||||
return false;
|
||||
} else if (lPlayer.playerType === 'howler') {
|
||||
// Check that the seek number is less than the duration
|
||||
if (seekTime < 0 || seekTime > lPlayer.playerObject._duration) {
|
||||
return false;
|
||||
}
|
||||
|
||||
lPlayer.playerObject.seek(seektime)
|
||||
}
|
||||
|
||||
lPlayer.playerObject.seek(seektime)
|
||||
}
|
||||
|
||||
}
|
||||
mstreamModule.seekByPercentage = function (percentage) {
|
||||
if (percentage < 0 || percentage > 99) {
|
||||
return false;
|
||||
}
|
||||
var lPlayer = getCurrentPlayer();
|
||||
|
||||
if (lPlayer.playerType === 'aurora') {
|
||||
// Do nothing, auroradoesn't support seeking
|
||||
return false;
|
||||
} else if (lPlayer.playerType === 'howler') {
|
||||
var seektime = (percentage * lPlayer.playerObject._duration) / 100;
|
||||
lPlayer.playerObject.seek(seektime)
|
||||
}
|
||||
|
||||
mstreamModule.seekByPercentage = function(percentage){
|
||||
if(percentage < 0 || percentage > 99){
|
||||
return false;
|
||||
}
|
||||
var lPlayer = getCurrentPlayer();
|
||||
|
||||
if(lPlayer.playerType === 'aurora' ){
|
||||
// Do nothing, auroradoesn't support seeking
|
||||
return false;
|
||||
}else if(lPlayer.playerType === 'howler'){
|
||||
var seektime = (percentage * lPlayer.playerObject._duration)/ 100;
|
||||
lPlayer.playerObject.seek(seektime)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -651,17 +657,17 @@ mstreamModule.seekByPercentage = function(percentage){
|
||||
if (timers.sliderUpdateInterval) { clearInterval(timers.sliderUpdateInterval); }
|
||||
|
||||
|
||||
timers.sliderUpdateInterval = setInterval( function(){
|
||||
timers.sliderUpdateInterval = setInterval(function () {
|
||||
var lPlayer = getCurrentPlayer();
|
||||
|
||||
if(lPlayer.playerType === 'aurora' ){
|
||||
if (lPlayer.playerType === 'aurora') {
|
||||
mstreamModule.playerStats.duration = lPlayer.playerObject.duration / 1000;
|
||||
mstreamModule.playerStats.currentTime = lPlayer.playerObject.currentTime / 1000;
|
||||
}else if(lPlayer.playerType === 'howler'){
|
||||
mstreamModule.playerStats.currentTime = lPlayer.playerObject.seek();
|
||||
} else if (lPlayer.playerType === 'howler') {
|
||||
mstreamModule.playerStats.currentTime = lPlayer.playerObject.seek();
|
||||
mstreamModule.playerStats.duration = lPlayer.playerObject._duration;
|
||||
|
||||
}else{
|
||||
} else {
|
||||
// NO PLAYER, set default values
|
||||
mstreamModule.playerStats.currentTime = 0;
|
||||
mstreamModule.playerStats.duration = 0;
|
||||
@ -671,17 +677,17 @@ mstreamModule.seekByPercentage = function(percentage){
|
||||
}
|
||||
startTime(100);
|
||||
|
||||
function clearTimer(){
|
||||
function clearTimer() {
|
||||
clearInterval(timers.sliderUpdateInterval);
|
||||
}
|
||||
|
||||
|
||||
// Timer for caching. Helps prevent excess cahing due to button mashing
|
||||
var cacheTimer;
|
||||
function setCachedSong(position){
|
||||
function setCachedSong(position) {
|
||||
|
||||
console.log(' ATTEMPTING TO CACHE');
|
||||
if(!mstreamModule.playlist[position]){
|
||||
if (!mstreamModule.playlist[position]) {
|
||||
console.log(' FAILED TO CACHE');
|
||||
return false;
|
||||
}
|
||||
@ -697,15 +703,15 @@ mstreamModule.seekByPercentage = function(percentage){
|
||||
|
||||
// Loop
|
||||
mstreamModule.playerStats.shouldLoop = false;
|
||||
mstreamModule.setRepeat = function(newValue){
|
||||
if(typeof(newValue) != "boolean"){
|
||||
mstreamModule.setRepeat = function (newValue) {
|
||||
if (typeof (newValue) != "boolean") {
|
||||
return false;
|
||||
}
|
||||
mstreamModule.playerStats.shouldLoop = newValue;
|
||||
return newValue;
|
||||
}
|
||||
mstreamModule.toggleRepeat = function(){
|
||||
mstreamModule.playerStats.shouldLoop = !mstreamModule.playerStats.shouldLoop;
|
||||
mstreamModule.toggleRepeat = function () {
|
||||
mstreamModule.playerStats.shouldLoop = !mstreamModule.playerStats.shouldLoop;
|
||||
return mstreamModule.playerStats.shouldLoop;
|
||||
}
|
||||
|
||||
@ -713,35 +719,35 @@ mstreamModule.seekByPercentage = function(percentage){
|
||||
mstreamModule.playerStats.shuffle = false;
|
||||
shuffleCache = []; // Cache the last 5 songs played to avoid repeats
|
||||
shufflePrevious = [];
|
||||
mstreamModule.setShuffle = function(newValue){
|
||||
if(typeof(newValue) != "boolean"){
|
||||
mstreamModule.setShuffle = function (newValue) {
|
||||
if (typeof (newValue) != "boolean") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(newValue===true){
|
||||
if (newValue === true) {
|
||||
newShuffle();
|
||||
}else{
|
||||
} else {
|
||||
turnShuffleOff();
|
||||
}
|
||||
|
||||
mstreamModule.playerStats.shuffle = newValue;
|
||||
return true;
|
||||
}
|
||||
mstreamModule.toggleShuffle = function(){
|
||||
mstreamModule.playerStats.shuffle = !mstreamModule.playerStats.shuffle;
|
||||
if(mstreamModule.playerStats.shuffle === true){
|
||||
mstreamModule.toggleShuffle = function () {
|
||||
mstreamModule.playerStats.shuffle = !mstreamModule.playerStats.shuffle;
|
||||
if (mstreamModule.playerStats.shuffle === true) {
|
||||
newShuffle();
|
||||
}else{
|
||||
} else {
|
||||
turnShuffleOff();
|
||||
}
|
||||
return mstreamModule.playerStats.shuffle;
|
||||
}
|
||||
|
||||
function newShuffle(){
|
||||
function newShuffle() {
|
||||
shuffleCache = shuffle(mstreamModule.playlist.slice(0));
|
||||
}
|
||||
|
||||
function turnShuffleOff(){
|
||||
function turnShuffleOff() {
|
||||
shufflePrevious = [];
|
||||
shuffleCache = [];
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
var VUEPLAYER = function () {
|
||||
|
||||
var currentPopperSongIndex2;
|
||||
var currentPopperSongIndex;
|
||||
var currentPopperSong;
|
||||
|
||||
@ -8,7 +9,6 @@ var VUEPLAYER = function () {
|
||||
if (!($(e.target).hasClass("pop-c"))) {
|
||||
$("#pop").css("visibility", "hidden");
|
||||
currentPopperSongIndex = false;
|
||||
songForating = false;
|
||||
}
|
||||
});
|
||||
|
||||
@ -48,25 +48,34 @@ var VUEPLAYER = function () {
|
||||
createPopper: function (event) {
|
||||
if (currentPopperSongIndex === this.index) {
|
||||
currentPopperSongIndex = false;
|
||||
songForating = false;
|
||||
$("#pop").css("visibility", "hidden");
|
||||
return;
|
||||
}
|
||||
var ref = event.target;
|
||||
currentPopperSongIndex = this.index;
|
||||
currentPopperSongIndex2 = this.index;
|
||||
|
||||
currentPopperSong = this.song;
|
||||
console.log(this.song)
|
||||
console.log(this.song.metadata.rating)
|
||||
|
||||
var offsetTopModifier = function (data) {
|
||||
data.offsets.popper.left += 20
|
||||
return data;
|
||||
}
|
||||
|
||||
const pop = document.getElementById('pop');
|
||||
var popper = new Popper(ref, pop, {
|
||||
placement: 'bowrgwr',
|
||||
onCreate: function (data) {
|
||||
// console.log(data);
|
||||
$("#pop").css("visibility", "visible");
|
||||
|
||||
},
|
||||
placement: 'left',
|
||||
modifiers: {
|
||||
flip: {
|
||||
boundariesElement: 'scrollParent',
|
||||
},
|
||||
preventOverflow: {
|
||||
boundariesElement: 'scrollParent'
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
@ -358,10 +367,7 @@ var VUEPLAYER = function () {
|
||||
activeColor: '#6684b2',
|
||||
ratedColor: '#6684b2',
|
||||
callback: function (currentRating, $el) {
|
||||
console.log(currentPopperSong.metadata.rating)
|
||||
console.log(JSON.stringify(currentPopperSong.metadata));
|
||||
|
||||
currentPopperSong.metadata.rating = parseInt(currentRating * 2);
|
||||
MSTREAMPLAYER.editSongMetadata('rating', parseInt(currentRating * 2), currentPopperSongIndex2);
|
||||
|
||||
// make a server call here
|
||||
MSTREAMAPI.rateSong(currentPopperSong.filepath, parseInt(currentRating * 2), function (res, err) {
|
||||
|
||||
@ -192,7 +192,6 @@
|
||||
<li class="left-off-canvas-toggle" id="jukebox_mode">
|
||||
<label>Jukebox</label>
|
||||
</li>
|
||||
<div class="my-rating"></div>
|
||||
</ul>
|
||||
|
||||
<div class="db-status-bar">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user