Skip to content
5 changes: 4 additions & 1 deletion widget/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 16 additions & 8 deletions widget/controllers/widget.home.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
dateIndexed: true,
dateCreatedIndexed: true,
enableFiltering: false,
allowOfflineDownload: true
},
design: {
listLayout: "list-1",
Expand Down Expand Up @@ -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 ?
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -1275,6 +1283,7 @@
mediaType: mediaType,
mediaPath: filePath,
dropboxAudioUpdated: true,
audioDownloadUpdated: true,
originalMediaUrl: mediaType == 'video' ? item.data.videoUrl : item.data.audioUrl,
createdOn: new Date(),
}
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion widget/controllers/widget.media.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
70 changes: 51 additions & 19 deletions widget/controllers/widget.nowplaying.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -732,6 +753,9 @@
NowPlaying.playList = data.tracks;
if (!$scope.$$phase) {
$scope.$digest();
if(typeof $rootScope.audioFromPlayList === 'number' ){
NowPlaying.playList[$rootScope.audioFromPlayList].playing = true;
}
}
}
});
Expand Down Expand Up @@ -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);
Expand All @@ -954,6 +985,7 @@
else {
NowPlaying.playlistPlay(track, index);
}
$rootScope.audioFromPlayList = index;
};

/**
Expand Down
5 changes: 4 additions & 1 deletion widget/downloadHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions widget/js/data/offlineMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
}
Expand Down
2 changes: 2 additions & 0 deletions widget/js/shared/offlineAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}))
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion widget/templates/layouts/now-playing.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ <h4 class="margin-zero ellipsis whiteTheme">{{NowPlaying.currentTrack.title}}</h
</div>
<div class="btns text-center">
<a ng-class="track.playing ? 'icon-pause-circle' : 'icon-play-circle'"
class="icon primaryTheme" ng-click="NowPlaying.playlistPlayPause(track)"></a>
class="icon primaryTheme" ng-click="NowPlaying.playlistPlayPause(track, $index)"></a>
</div>
<div class="remove-btn text-center dangerBackgroundTheme" style="background:red;"
ng-click="NowPlaying.removeTrackFromPlayList($index)">
Expand Down