Skip to content

Commit 0d88284

Browse files
authored
Merge pull request #226 from BuildFire/white-screen-offline-download-playlist-fix
White screen offline download playlist fix
2 parents 38fc843 + 49e4f5b commit 0d88284

File tree

8 files changed

+79
-31
lines changed

8 files changed

+79
-31
lines changed

widget/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
}
7474
if (res) {
7575
res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated)))
76+
res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS")))
7677

7778
let matchingItems = res.filter(item => item.mediaId == mediaId);
7879
if (matchingItems.length > 0) {
@@ -149,7 +150,8 @@
149150
}
150151
if (res) {
151152
res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated)))
152-
153+
res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS")))
154+
153155
let matchingItems = res.filter(item => item.mediaId == mediaId);
154156
if (matchingItems.length > 0) {
155157
matchingItems.map(downloadedItem => {
@@ -249,6 +251,7 @@
249251
if (err) {}
250252
if (res) {
251253
res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated)))
254+
res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS")))
252255

253256
let matchingItems = res.filter(item => item.mediaId == mediaId);
254257
if (matchingItems.length > 0) {

widget/controllers/widget.home.controller.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
dateIndexed: true,
6262
dateCreatedIndexed: true,
6363
enableFiltering: false,
64+
allowOfflineDownload: true
6465
},
6566
design: {
6667
listLayout: "list-1",
@@ -792,7 +793,8 @@
792793
DownloadedMedia.get((err, res) => {
793794
let downloadedIDS = [];
794795
if (err || (!res && !res.length)) return callback(err, null);
795-
res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated)))
796+
res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated)));
797+
res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS")));
796798

797799
downloadedIDS = res.map(item => item.mediaId);
798800
downloadedIDS.length ?
@@ -868,6 +870,7 @@
868870
}
869871
if (res) {
870872
res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated)))
873+
res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS")))
871874

872875
downloadedIDS = res.map(item => item.mediaId);
873876
if (downloadedIDS.length > 0) {
@@ -1247,17 +1250,22 @@
12471250
return;
12481251
}
12491252
beginDownload(() => {
1250-
let { uri, type, source } = mediaType == 'video' ? WidgetHome.getVideoDownloadURL(item.data.videoUrl)
1253+
// Use "returnAsWebUri" property for downloaded videos on IOS to enable playback, but avoid using it for downloaded audio files as it may cause errors.
1254+
let returnAsWebUri= false;
1255+
let { uri, type, source } = mediaType == 'video' ? (
1256+
returnAsWebUri= true,
1257+
WidgetHome.getVideoDownloadURL(item.data.videoUrl)
1258+
)
12511259
: WidgetHome.getAudioDownloadURL(item.data.audioUrl);
12521260
if (source && (source === 'youtube' || source === 'vimeo')) return downloadInvalid();
12531261
$rootScope.currentlyDownloading.push(item.id);
12541262
if (!$rootScope.$$phase && !$rootScope.$root.$$phase) $rootScope.$apply();
12551263
buildfire.services.fileSystem.fileManager.download(
12561264
{
1257-
uri: uri,
1265+
uri,
12581266
path: "/data/mediaCenterManual/" + Buildfire.getContext().instanceId + "/" + mediaType + "/",
12591267
fileName: item.id + "." + type,
1260-
returnAsWebUri: true
1268+
returnAsWebUri
12611269
},
12621270
(err, filePath) => {
12631271
if (err) {
@@ -1275,6 +1283,7 @@
12751283
mediaType: mediaType,
12761284
mediaPath: filePath,
12771285
dropboxAudioUpdated: true,
1286+
audioDownloadUpdated: true,
12781287
originalMediaUrl: mediaType == 'video' ? item.data.videoUrl : item.data.audioUrl,
12791288
createdOn: new Date(),
12801289
}
@@ -1513,12 +1522,11 @@
15131522
CachedMediaCenter.get((err, res) => {
15141523
if (err) {
15151524
WidgetHome.media = _infoData;
1516-
}
1517-
1518-
else {
1525+
}else {
15191526
WidgetHome.media = res;
1520-
WidgetHome.loadMore();
15211527
}
1528+
1529+
WidgetHome.loadMore();
15221530
setTimeout(() => {
15231531
if (!$scope.$$phase && !$scope.$root.$$phase) $scope.$apply();
15241532
}, 0);

widget/controllers/widget.media.controller.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@
507507
WidgetMedia.item.srcUrl = media.data.srcUrl ? media.data.srcUrl
508508
: (media.data.audioUrl ? media.data.audioUrl : media.data.videoUrl);
509509
bookmarks.sync($scope);
510-
if (!WidgetMedia.isWeb) downloads.sync($scope, DownloadedMedia);
511510
WidgetMedia.changeVideoSrc();
512511

513512
WidgetMedia.iframeSrcUrl = $sce.trustAsUrl(WidgetMedia.item.data.srcUrl);

widget/controllers/widget.nowplaying.controller.js

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,14 @@
257257
*/
258258
//var first = true;
259259
var ready = false, setOder = false, first = false, open = true;
260-
audioPlayer.onEvent(function (e) {
260+
if($rootScope.activePlayerEvents){
261+
// Prevent the repetition of events by clearing all previous occurrences, as repeated events tend to occur when the user plays multiple audio files.
262+
$rootScope.activePlayerEvents.clear();
263+
}
264+
$rootScope.activePlayerEvents = audioPlayer.onEvent(function (e) {
261265
switch (e.event) {
262266
case 'play':
267+
NowPlaying.currentTrack = e.data.track;
263268
NowPlaying.playing = true;
264269
NowPlaying.paused = false;
265270
audioPlayer.getPlaylist(function (err, data) {
@@ -322,6 +327,10 @@
322327
case 'audioEnded':
323328
ready = false;
324329
updateAudioMediaCount(media.id, 0.1)
330+
if(typeof $rootScope.audioFromPlayList === 'number'){
331+
NowPlaying.playlistPause(NowPlaying.playList[$rootScope.audioFromPlayList]);
332+
return false;
333+
}
325334
if ($rootScope.autoPlay) {
326335
$rootScope.playNextItem();
327336
} else {
@@ -368,19 +377,22 @@
368377
NowPlaying.playing = false;
369378
break;
370379
case 'next':
371-
if ($rootScope.autoPlay) {
372-
// param: userInput
373-
$rootScope.playNextItem(true);
374-
} else if (e && e.data && e.data.track) {
375-
e.data.track.lastPosition = 0;
376-
NowPlaying.currentTrack = e.data.track;
377-
NowPlaying.playing = true;
378-
} else {
379-
// param: userInput
380-
$rootScope.playNextItem(true);
380+
if(typeof $rootScope.audioFromPlayList === 'number'){
381+
$rootScope.audioFromPlayList = e.data.index;
382+
NowPlaying.playList[$rootScope.audioFromPlayList].playing = true;
383+
if(!NowPlaying.settings.autoJumpToLastPosition){
384+
audioPlayer.setTime(0);
385+
}
386+
return false;
381387
}
382388
break;
383389
case 'previous':
390+
if(typeof $rootScope.audioFromPlayList === 'number' && NowPlaying.settings.autoPlayNext){
391+
$rootScope.audioFromPlayList = e.data.index;
392+
NowPlaying.playList[$rootScope.audioFromPlayList].playing = true;
393+
audioPlayer.setTime(0);
394+
return false;
395+
}
384396
$rootScope.playPrevItem();
385397
break;
386398
case 'removeFromPlaylist':
@@ -570,8 +582,8 @@
570582
audioPlayer.play(index);
571583
}
572584
else {
585+
$rootScope.audioFromPlayList = null;
573586
if (isAudioEnded) {
574-
console.log("Hi2")
575587
NowPlaying.currentTrack.lastPosition = 0
576588
}
577589
NowPlaying.currentTrack.url = validateURL(NowPlaying.currentTrack.url);
@@ -593,15 +605,16 @@
593605
}
594606

595607

596-
NowPlaying.playlistPlay = function (track) {
608+
NowPlaying.playlistPlay = function (track, index) {
597609
if (NowPlaying.settings) {
598610
NowPlaying.settings.isPlayingCurrentTrack = true;
599611
audioPlayer.settings.set(NowPlaying.settings);
600612
}
601613
NowPlaying.playing = true;
602-
if (track) {
603-
track.url = validateURL(track.url)
604-
audioPlayer.play({ url: track.url });
614+
if (typeof index==='number') {
615+
NowPlaying.isAudioPlayerPlayingAnotherSong = false;
616+
audioPlayer.pause();
617+
audioPlayer.play(index);
605618
track.playing = true;
606619
}
607620
if (!$scope.$$phase) {
@@ -650,11 +663,19 @@
650663
};
651664

652665
NowPlaying.next = function () {
653-
$rootScope.playNextItem(true);
666+
if(typeof $rootScope.audioFromPlayList === 'number'){
667+
audioPlayer.next();
668+
}else{
669+
$rootScope.playNextItem(true);
670+
}
654671
};
655672

656673
NowPlaying.prev = function () {
657-
$rootScope.playPrevItem();
674+
if(typeof $rootScope.audioFromPlayList === 'number'){
675+
audioPlayer.previous();
676+
}else{
677+
$rootScope.playPrevItem();
678+
}
658679
};
659680

660681
NowPlaying.shufflePlaylist = function () {
@@ -732,6 +753,9 @@
732753
NowPlaying.playList = data.tracks;
733754
if (!$scope.$$phase) {
734755
$scope.$digest();
756+
if(typeof $rootScope.audioFromPlayList === 'number' ){
757+
NowPlaying.playList[$rootScope.audioFromPlayList].playing = true;
758+
}
735759
}
736760
}
737761
});
@@ -941,11 +965,18 @@
941965
}
942966
}
943967
else if (NowPlaying.paused) {
968+
NowPlaying.playList.forEach(element => {
969+
element.playing = false
970+
});
944971
if (track.url == NowPlaying.currentTrack.url) {
945972
NowPlaying.settings.isPlayingCurrentTrack = true;
946973
NowPlaying.playing = true;
947974
track.playing = true;
948-
audioPlayer.play();
975+
if($rootScope.audioFromPlayList == index){
976+
audioPlayer.play();
977+
}else{
978+
audioPlayer.play(index);
979+
}
949980
}
950981
else {
951982
NowPlaying.playlistPlay(track, index);
@@ -954,6 +985,7 @@
954985
else {
955986
NowPlaying.playlistPlay(track, index);
956987
}
988+
$rootScope.audioFromPlayList = index;
957989
};
958990

959991
/**

widget/downloadHandler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ var downloads = {
1414
if (res) {
1515
// filtering old dropbox audio downloaded links, removing them from the "response"
1616
res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated)))
17-
17+
18+
// filtering old iOS audio downloaded links, removing them from the "response"
19+
res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS")))
20+
1821
downloadedIDS = res.map(a => a.mediaId);
1922
if ($scope.WidgetHome) {
2023
$scope.WidgetHome.item = $scope.WidgetHome.items.map(item => {

widget/js/data/offlineMedia.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class OfflineMedia {
66
this.mediaPath = data.mediaPath || '';
77
this.originalMediaUrl = data.originalMediaUrl || '';
88
this.dropboxAudioUpdated = typeof(data.dropboxAudioUpdated)==='boolean' ? data.dropboxAudioUpdated : false;
9+
this.audioDownloadUpdated = typeof(data.audioDownloadUpdated)==='boolean' ? data.audioDownloadUpdated : false;
910
this.createdOn = data.createdOn || '';
1011
this.lastUpdatedOn = data.lastUpdatedOn || '';
1112
}

widget/js/shared/offlineAccess.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class OfflineAccess {
2626
mediaPath: data.mediaPath,
2727
originalMediaUrl: data.originalMediaUrl,
2828
dropboxAudioUpdated: data.dropboxAudioUpdated,
29+
audioDownloadUpdated: data.audioDownloadUpdated,
2930
createdOn: data.createdOn || new Date(),
3031
lastUpdatedOn: new Date(),
3132
}))
@@ -59,6 +60,7 @@ class OfflineAccess {
5960
mediaId: data.mediaId,
6061
mediaType: data.mediaType,
6162
dropboxAudioUpdated: data.dropboxAudioUpdated,
63+
audioDownloadUpdated: data.audioDownloadUpdated,
6264
mediaPath: data.mediaPath,
6365
createdOn: data.createdOn,
6466
lastUpdatedOn: new Date(),

widget/templates/layouts/now-playing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ <h4 class="margin-zero ellipsis whiteTheme">{{NowPlaying.currentTrack.title}}</h
123123
</div>
124124
<div class="btns text-center">
125125
<a ng-class="track.playing ? 'icon-pause-circle' : 'icon-play-circle'"
126-
class="icon primaryTheme" ng-click="NowPlaying.playlistPlayPause(track)"></a>
126+
class="icon primaryTheme" ng-click="NowPlaying.playlistPlayPause(track, $index)"></a>
127127
</div>
128128
<div class="remove-btn text-center dangerBackgroundTheme" style="background:red;"
129129
ng-click="NowPlaying.removeTrackFromPlayList($index)">

0 commit comments

Comments
 (0)