Skip to content

Commit b98fea9

Browse files
authored
Merge pull request #245 from BuildFire/fix/hidden-playlist
Fix/hidden playlist - PLUG-2817
2 parents 4008647 + cd69c88 commit b98fea9

File tree

3 files changed

+32
-35
lines changed

3 files changed

+32
-35
lines changed

widget/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@
379379
if (path.indexOf('/media') == 0 || path.indexOf('/filters') == 0) {
380380
navigate();
381381
} else if (path.indexOf('/nowplaying') == 0) {
382-
if ($rootScope.playlist) {
383-
$rootScope.playlist = false;
382+
if ($rootScope.showPlaylist) {
383+
$rootScope.showPlaylist = false;
384384
$rootScope.$digest();
385385
} else if ($rootScope.skipMediaPage) {
386386
navigate();

widget/controllers/widget.nowplaying.controller.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
*/
129129

130130
function convertDropbox(obj) {
131-
if (obj.includes("www.dropbox") || obj.includes("dl.dropbox.com")) {
131+
if (obj && (obj.includes("www.dropbox") || obj.includes("dl.dropbox.com"))) {
132132
obj = obj.replace("www.dropbox", "dl.dropbox").replace("dl.dropbox.com", "dl.dropboxusercontent.com");
133133
}
134134
return obj;
@@ -197,10 +197,10 @@
197197
plugin: buildfire.context.instanceId, myId: el.id
198198
};
199199
});
200-
NowPlaying.playList = [];
200+
$rootScope.playListItems = [];
201201
for (var i = 0; i < pluginSongs.length; i++) {
202202
audioPlayer.addToPlaylist(pluginSongs[i]);
203-
NowPlaying.playList.push(pluginSongs[i]);
203+
$rootScope.playListItems.push(pluginSongs[i]);
204204
}
205205
}
206206
} else {
@@ -358,19 +358,19 @@
358358
ready = false;
359359
updateAudioLastPosition(media.id, 0.1)
360360
if(typeof $rootScope.audioFromPlayList === 'number'){
361-
NowPlaying.playlistPause(NowPlaying.playList[$rootScope.audioFromPlayList]);
361+
NowPlaying.playlistPause($rootScope.playListItems[$rootScope.audioFromPlayList]);
362362
return false;
363363
}
364364
if ($rootScope.autoPlay) {
365365
$rootScope.playNextItem();
366366
} else {
367367
if (NowPlaying.isItLast && NowPlaying.settings.loopPlaylist) {
368368
audioPlayer.getCurrentTrack((track) => {
369-
if (NowPlaying.playList && NowPlaying.playList.length > 0) {
370-
NowPlaying.playList.forEach(element => {
369+
if ($rootScope.playListItems && $rootScope.playListItems.length > 0) {
370+
$rootScope.playListItems.forEach(element => {
371371
element.playing = false
372372
});
373-
let currentTrack = NowPlaying.playList.find(x => x.title == track.title && x.url == track.url && x.album == track.album && x.image == track.image && x.backgroundImage == track.backgroundImage)
373+
let currentTrack = $rootScope.playListItems.find(x => x.title == track.title && x.url == track.url && x.album == track.album && x.image == track.image && x.backgroundImage == track.backgroundImage)
374374
if (currentTrack) {
375375
currentTrack.playing = true
376376
}
@@ -409,7 +409,7 @@
409409
case 'next':
410410
if(typeof $rootScope.audioFromPlayList === 'number'){
411411
$rootScope.audioFromPlayList = e.data.index;
412-
NowPlaying.playList[$rootScope.audioFromPlayList].playing = true;
412+
$rootScope.playListItems[$rootScope.audioFromPlayList].playing = true;
413413
if(!NowPlaying.settings.autoJumpToLastPosition){
414414
audioPlayer.setTime(0);
415415
}
@@ -419,14 +419,15 @@
419419
case 'previous':
420420
if(typeof $rootScope.audioFromPlayList === 'number' && NowPlaying.settings.autoPlayNext){
421421
$rootScope.audioFromPlayList = e.data.index;
422-
NowPlaying.playList[$rootScope.audioFromPlayList].playing = true;
422+
$rootScope.playListItems[$rootScope.audioFromPlayList].playing = true;
423423
audioPlayer.setTime(0);
424424
return false;
425425
}
426426
$rootScope.playPrevItem();
427427
break;
428428
case 'removeFromPlaylist':
429-
NowPlaying.playList = e.data && e.data.newPlaylist && e.data.newPlaylist.tracks;
429+
case 'addToPlaylist':
430+
$rootScope.playListItems = e.data.newPlaylist.tracks;
430431
break;
431432

432433
}
@@ -675,7 +676,6 @@
675676
if (isAudioEnded) {
676677
NowPlaying.currentTrack.lastPosition = 0
677678
}
678-
NowPlaying.currentTrack.url = validateURL(NowPlaying.currentTrack.url);
679679
audioPlayer.play(NowPlaying.currentTrack);
680680
audioPlayer.pause();
681681
setTimeout(() => {
@@ -809,8 +809,8 @@
809809
buildfire.dialog.toast({
810810
message: NowPlaying.playListStrings.removedFromPlaylist
811811
});
812-
if (NowPlaying.playList) {
813-
NowPlaying.playList.filter(function (val, index) {
812+
if ($rootScope.playListItems) {
813+
$rootScope.playListItems.filter(function (val, index) {
814814
if (val.url == track.url) {
815815
audioPlayer.removeFromPlaylist(index);
816816
}
@@ -836,21 +836,24 @@
836836
});
837837

838838
};
839-
NowPlaying.getFromPlaylist = function () {
839+
NowPlaying.showPlaylistPage = function () {
840+
NowPlaying.openMoreInfo = false;
841+
$rootScope.showPlaylist = true;
842+
}
843+
NowPlaying.getPlaylistData = function (openPlaylist = false) {
840844
audioPlayer.getPlaylist(function (err, data) {
841845
if (data && data.tracks) {
842-
NowPlaying.playList = data.tracks;
846+
$rootScope.playListItems = data.tracks;
843847
if (!$scope.$$phase) {
844848
$scope.$digest();
845849
if(typeof $rootScope.audioFromPlayList === 'number' ){
846-
NowPlaying.playList[$rootScope.audioFromPlayList].playing = true;
850+
$rootScope.playListItems[$rootScope.audioFromPlayList].playing = true;
847851
}
848852
}
849853
}
850854
});
851-
NowPlaying.openMoreInfo = false;
852-
$rootScope.playlist = true;
853855
};
856+
NowPlaying.getPlaylistData();
854857
NowPlaying.changeTime = function (time) {
855858
audioPlayer.setTime(time);
856859
};
@@ -886,7 +889,7 @@
886889
NowPlaying.openSettings = false;
887890
};
888891
NowPlaying.closePlayListOverlay = function () {
889-
$rootScope.playlist = false;
892+
$rootScope.showPlaylist = false;
890893
};
891894
NowPlaying.closeMoreInfoOverlay = function () {
892895
NowPlaying.openMoreInfo = false;
@@ -896,12 +899,6 @@
896899
toggle ? track.swiped = true : track.swiped = false;
897900
};
898901

899-
// this method to make the audio url replaying multi times
900-
function validateURL(url) {
901-
if (url.includes('?')) return (url + '&' + Math.floor(Math.random() * 1000))
902-
return (url + '?' + Math.floor(Math.random() * 1000))
903-
}
904-
905902
/**
906903
* Track Smaple
907904
* @param title
@@ -1064,16 +1061,16 @@
10641061
NowPlaying.playlistPause(track);
10651062
}
10661063
else {
1067-
if (NowPlaying.playList && NowPlaying.playList.length > 0) {
1068-
NowPlaying.playList.forEach(element => {
1064+
if ($rootScope.playListItems && $rootScope.playListItems.length > 0) {
1065+
$rootScope.playListItems.forEach(element => {
10691066
element.playing = false
10701067
});
10711068
}
10721069
NowPlaying.playlistPlay(track, index);
10731070
}
10741071
}
10751072
else if (NowPlaying.paused) {
1076-
NowPlaying.playList.forEach(element => {
1073+
$rootScope.playListItems.forEach(element => {
10771074
element.playing = false
10781075
});
10791076
if (track.url == NowPlaying.currentTrack.url) {

widget/templates/layouts/now-playing.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h4 class="margin-zero ellipsis whiteTheme">{{NowPlaying.currentTrack.title}}</h
110110
<div class="media-player-action-btns">
111111
<span class="playback-speed whiteTheme" ng-click="NowPlaying.openPlaybackDrawer()">{{NowPlaying.settings.playbackSpeed || 1 | number:'1'}}x</span>
112112
<span ng-style="{'visibility': allowAddingNotes !== false ? 'visible' : 'hidden'}" class="glyphicon glyphicon-edit whiteTheme" ng-click="NowPlaying.addNote()"></span>
113-
<span ng-if="!globalPlaylist" class="btn btn-icon" ng-click="NowPlaying.getFromPlaylist()">
113+
<span ng-if="!globalPlaylist" class="btn btn-icon" ng-click="NowPlaying.showPlaylistPage()">
114114
<img class="playList-icon" src="assets/css/icons/ic_playlist.svg" alt="playlist">
115115
</span>
116116
<span ng-if="!globalPlaylist" class="glyphicon glyphicon-option-horizontal whiteTheme"
@@ -121,15 +121,15 @@ <h4 class="margin-zero ellipsis whiteTheme">{{NowPlaying.currentTrack.title}}</h
121121
</div>
122122

123123
<!-- Playlist Overlay -->
124-
<div ng-if="playlist" class="overlay backgroundColorTheme slide"
124+
<div ng-if="showPlaylist" class="overlay backgroundColorTheme slide"
125125
style="position:fixed; top:0; left:0; width:100%; height:100%;">
126126
<div class="overlay-content" style="position:absolute; top:0; left:0; height:100%; width: 100%; overflow:auto;">
127127
<div class="media-player-list-layout third-layout">
128128
<div class="list-layout has-btns">
129129
<div class="list-item overflow-hidden"
130130
ng-swipe-right="NowPlaying.addEvents($event, $index, false,track)"
131131
ng-swipe-left="NowPlaying.addEvents($event, $index, true,track)"
132-
ng-repeat="track in NowPlaying.playList">
132+
ng-repeat="track in playListItems">
133133
<div class="list-item-media text-left" ng-class="{'edit' : track.swiped}">
134134
<div class="list-media-holder square-icon pull-left">
135135
<img ng-if="track.image" load-image="2x1" crop-width="55" crop-height="22"
@@ -149,7 +149,7 @@ <h4 class="margin-zero ellipsis whiteTheme">{{NowPlaying.currentTrack.title}}</h
149149
</div>
150150
</div>
151151
</div>
152-
<div ng-if="!NowPlaying.playList.length">
152+
<div ng-if="!playListItems.length">
153153
<h3 class="ellipsis">{{NowPlaying.playListStrings.emptyPlaylist}}</h3>
154154
</div>
155155
</div>
@@ -180,7 +180,7 @@ <h4 class="margin-zero ellipsis whiteTheme">{{NowPlaying.currentTrack.title}}</h
180180
<hr class="none">
181181
<div class="more-info-list padded">
182182
<div class="text-center item">
183-
<a ng-click="NowPlaying.getFromPlaylist()" class="whiteTheme">{{NowPlaying.playListStrings.goToPlaylist}}</a>
183+
<a ng-click="NowPlaying.showPlaylistPage()" class="whiteTheme">{{NowPlaying.playListStrings.goToPlaylist}}</a>
184184
</div>
185185
<div class="text-center item" ng-if="!NowPlaying.transferPlaylist">
186186
<a ng-click="NowPlaying.addToPlaylist(NowPlaying.currentTrack)" class="whiteTheme">{{NowPlaying.playListStrings.addToPlaylist}}</a>

0 commit comments

Comments
 (0)