diff --git a/widget/app.js b/widget/app.js index 85d6cb2e..d3bf9a2d 100644 --- a/widget/app.js +++ b/widget/app.js @@ -73,6 +73,7 @@ } if (res) { res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated))) + res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS"))) let matchingItems = res.filter(item => item.mediaId == mediaId); if (matchingItems.length > 0) { @@ -149,7 +150,8 @@ } if (res) { res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated))) - + res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS"))) + let matchingItems = res.filter(item => item.mediaId == mediaId); if (matchingItems.length > 0) { matchingItems.map(downloadedItem => { @@ -249,6 +251,7 @@ if (err) {} if (res) { res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated))) + res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS"))) let matchingItems = res.filter(item => item.mediaId == mediaId); if (matchingItems.length > 0) { diff --git a/widget/controllers/widget.home.controller.js b/widget/controllers/widget.home.controller.js index 681dac01..776b8706 100644 --- a/widget/controllers/widget.home.controller.js +++ b/widget/controllers/widget.home.controller.js @@ -61,6 +61,7 @@ dateIndexed: true, dateCreatedIndexed: true, enableFiltering: false, + allowOfflineDownload: true }, design: { listLayout: "list-1", @@ -792,7 +793,8 @@ DownloadedMedia.get((err, res) => { let downloadedIDS = []; if (err || (!res && !res.length)) return callback(err, null); - res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated))) + res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated))); + res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS"))); downloadedIDS = res.map(item => item.mediaId); downloadedIDS.length ? @@ -868,6 +870,7 @@ } if (res) { res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated))) + res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS"))) downloadedIDS = res.map(item => item.mediaId); if (downloadedIDS.length > 0) { @@ -1247,17 +1250,22 @@ return; } beginDownload(() => { - let { uri, type, source } = mediaType == 'video' ? WidgetHome.getVideoDownloadURL(item.data.videoUrl) + // Use "returnAsWebUri" property for downloaded videos on IOS to enable playback, but avoid using it for downloaded audio files as it may cause errors. + let returnAsWebUri= false; + let { uri, type, source } = mediaType == 'video' ? ( + returnAsWebUri= true, + WidgetHome.getVideoDownloadURL(item.data.videoUrl) + ) : WidgetHome.getAudioDownloadURL(item.data.audioUrl); if (source && (source === 'youtube' || source === 'vimeo')) return downloadInvalid(); $rootScope.currentlyDownloading.push(item.id); if (!$rootScope.$$phase && !$rootScope.$root.$$phase) $rootScope.$apply(); buildfire.services.fileSystem.fileManager.download( { - uri: uri, + uri, path: "/data/mediaCenterManual/" + Buildfire.getContext().instanceId + "/" + mediaType + "/", fileName: item.id + "." + type, - returnAsWebUri: true + returnAsWebUri }, (err, filePath) => { if (err) { @@ -1275,6 +1283,7 @@ mediaType: mediaType, mediaPath: filePath, dropboxAudioUpdated: true, + audioDownloadUpdated: true, originalMediaUrl: mediaType == 'video' ? item.data.videoUrl : item.data.audioUrl, createdOn: new Date(), } @@ -1513,12 +1522,11 @@ CachedMediaCenter.get((err, res) => { if (err) { WidgetHome.media = _infoData; - } - - else { + }else { WidgetHome.media = res; - WidgetHome.loadMore(); } + + WidgetHome.loadMore(); setTimeout(() => { if (!$scope.$$phase && !$scope.$root.$$phase) $scope.$apply(); }, 0); diff --git a/widget/controllers/widget.media.controller.js b/widget/controllers/widget.media.controller.js index d05999fb..e949f70b 100644 --- a/widget/controllers/widget.media.controller.js +++ b/widget/controllers/widget.media.controller.js @@ -507,7 +507,6 @@ WidgetMedia.item.srcUrl = media.data.srcUrl ? media.data.srcUrl : (media.data.audioUrl ? media.data.audioUrl : media.data.videoUrl); bookmarks.sync($scope); - if (!WidgetMedia.isWeb) downloads.sync($scope, DownloadedMedia); WidgetMedia.changeVideoSrc(); WidgetMedia.iframeSrcUrl = $sce.trustAsUrl(WidgetMedia.item.data.srcUrl); diff --git a/widget/controllers/widget.nowplaying.controller.js b/widget/controllers/widget.nowplaying.controller.js index 8c6385c1..21e32731 100644 --- a/widget/controllers/widget.nowplaying.controller.js +++ b/widget/controllers/widget.nowplaying.controller.js @@ -257,9 +257,14 @@ */ //var first = true; var ready = false, setOder = false, first = false, open = true; - audioPlayer.onEvent(function (e) { + if($rootScope.activePlayerEvents){ + // Prevent the repetition of events by clearing all previous occurrences, as repeated events tend to occur when the user plays multiple audio files. + $rootScope.activePlayerEvents.clear(); + } + $rootScope.activePlayerEvents = audioPlayer.onEvent(function (e) { switch (e.event) { case 'play': + NowPlaying.currentTrack = e.data.track; NowPlaying.playing = true; NowPlaying.paused = false; audioPlayer.getPlaylist(function (err, data) { @@ -322,6 +327,10 @@ case 'audioEnded': ready = false; updateAudioMediaCount(media.id, 0.1) + if(typeof $rootScope.audioFromPlayList === 'number'){ + NowPlaying.playlistPause(NowPlaying.playList[$rootScope.audioFromPlayList]); + return false; + } if ($rootScope.autoPlay) { $rootScope.playNextItem(); } else { @@ -368,19 +377,22 @@ NowPlaying.playing = false; break; case 'next': - if ($rootScope.autoPlay) { - // param: userInput - $rootScope.playNextItem(true); - } else if (e && e.data && e.data.track) { - e.data.track.lastPosition = 0; - NowPlaying.currentTrack = e.data.track; - NowPlaying.playing = true; - } else { - // param: userInput - $rootScope.playNextItem(true); + if(typeof $rootScope.audioFromPlayList === 'number'){ + $rootScope.audioFromPlayList = e.data.index; + NowPlaying.playList[$rootScope.audioFromPlayList].playing = true; + if(!NowPlaying.settings.autoJumpToLastPosition){ + audioPlayer.setTime(0); + } + return false; } break; case 'previous': + if(typeof $rootScope.audioFromPlayList === 'number' && NowPlaying.settings.autoPlayNext){ + $rootScope.audioFromPlayList = e.data.index; + NowPlaying.playList[$rootScope.audioFromPlayList].playing = true; + audioPlayer.setTime(0); + return false; + } $rootScope.playPrevItem(); break; case 'removeFromPlaylist': @@ -570,8 +582,8 @@ audioPlayer.play(index); } else { + $rootScope.audioFromPlayList = null; if (isAudioEnded) { - console.log("Hi2") NowPlaying.currentTrack.lastPosition = 0 } NowPlaying.currentTrack.url = validateURL(NowPlaying.currentTrack.url); @@ -593,15 +605,16 @@ } - NowPlaying.playlistPlay = function (track) { + NowPlaying.playlistPlay = function (track, index) { if (NowPlaying.settings) { NowPlaying.settings.isPlayingCurrentTrack = true; audioPlayer.settings.set(NowPlaying.settings); } NowPlaying.playing = true; - if (track) { - track.url = validateURL(track.url) - audioPlayer.play({ url: track.url }); + if (typeof index==='number') { + NowPlaying.isAudioPlayerPlayingAnotherSong = false; + audioPlayer.pause(); + audioPlayer.play(index); track.playing = true; } if (!$scope.$$phase) { @@ -650,11 +663,19 @@ }; NowPlaying.next = function () { - $rootScope.playNextItem(true); + if(typeof $rootScope.audioFromPlayList === 'number'){ + audioPlayer.next(); + }else{ + $rootScope.playNextItem(true); + } }; NowPlaying.prev = function () { - $rootScope.playPrevItem(); + if(typeof $rootScope.audioFromPlayList === 'number'){ + audioPlayer.previous(); + }else{ + $rootScope.playPrevItem(); + } }; NowPlaying.shufflePlaylist = function () { @@ -732,6 +753,9 @@ NowPlaying.playList = data.tracks; if (!$scope.$$phase) { $scope.$digest(); + if(typeof $rootScope.audioFromPlayList === 'number' ){ + NowPlaying.playList[$rootScope.audioFromPlayList].playing = true; + } } } }); @@ -941,11 +965,18 @@ } } else if (NowPlaying.paused) { + NowPlaying.playList.forEach(element => { + element.playing = false + }); if (track.url == NowPlaying.currentTrack.url) { NowPlaying.settings.isPlayingCurrentTrack = true; NowPlaying.playing = true; track.playing = true; - audioPlayer.play(); + if($rootScope.audioFromPlayList == index){ + audioPlayer.play(); + }else{ + audioPlayer.play(index); + } } else { NowPlaying.playlistPlay(track, index); @@ -954,6 +985,7 @@ else { NowPlaying.playlistPlay(track, index); } + $rootScope.audioFromPlayList = index; }; /** diff --git a/widget/downloadHandler.js b/widget/downloadHandler.js index 60521533..84eb87bd 100644 --- a/widget/downloadHandler.js +++ b/widget/downloadHandler.js @@ -14,7 +14,10 @@ var downloads = { if (res) { // filtering old dropbox audio downloaded links, removing them from the "response" res = res.filter(item=>(!(item.mediaType==='audio' && (item.originalMediaUrl.includes("www.dropbox") || item.originalMediaUrl.includes("dl.dropbox")) && !item.dropboxAudioUpdated))) - + + // filtering old iOS audio downloaded links, removing them from the "response" + res = res.filter(item=>(!(item.mediaType==='audio' && !item.audioDownloadUpdated && buildfire.getContext().device.platform === "iOS"))) + downloadedIDS = res.map(a => a.mediaId); if ($scope.WidgetHome) { $scope.WidgetHome.item = $scope.WidgetHome.items.map(item => { diff --git a/widget/js/data/offlineMedia.js b/widget/js/data/offlineMedia.js index fb7bb48b..7980ab67 100644 --- a/widget/js/data/offlineMedia.js +++ b/widget/js/data/offlineMedia.js @@ -6,6 +6,7 @@ class OfflineMedia { this.mediaPath = data.mediaPath || ''; this.originalMediaUrl = data.originalMediaUrl || ''; this.dropboxAudioUpdated = typeof(data.dropboxAudioUpdated)==='boolean' ? data.dropboxAudioUpdated : false; + this.audioDownloadUpdated = typeof(data.audioDownloadUpdated)==='boolean' ? data.audioDownloadUpdated : false; this.createdOn = data.createdOn || ''; this.lastUpdatedOn = data.lastUpdatedOn || ''; } diff --git a/widget/js/shared/offlineAccess.js b/widget/js/shared/offlineAccess.js index 6a443bbe..cf257be2 100644 --- a/widget/js/shared/offlineAccess.js +++ b/widget/js/shared/offlineAccess.js @@ -26,6 +26,7 @@ class OfflineAccess { mediaPath: data.mediaPath, originalMediaUrl: data.originalMediaUrl, dropboxAudioUpdated: data.dropboxAudioUpdated, + audioDownloadUpdated: data.audioDownloadUpdated, createdOn: data.createdOn || new Date(), lastUpdatedOn: new Date(), })) @@ -59,6 +60,7 @@ class OfflineAccess { mediaId: data.mediaId, mediaType: data.mediaType, dropboxAudioUpdated: data.dropboxAudioUpdated, + audioDownloadUpdated: data.audioDownloadUpdated, mediaPath: data.mediaPath, createdOn: data.createdOn, lastUpdatedOn: new Date(), diff --git a/widget/templates/layouts/now-playing.html b/widget/templates/layouts/now-playing.html index fdbb1d28..7f58589c 100644 --- a/widget/templates/layouts/now-playing.html +++ b/widget/templates/layouts/now-playing.html @@ -123,7 +123,7 @@

{{NowPlaying.currentTrack.title}}
+ class="icon primaryTheme" ng-click="NowPlaying.playlistPlayPause(track, $index)">