|
@@ -1509,7 +1509,8 @@
|
|
$("#mainAudioPlayer").attr("src", playbackURL);
|
|
$("#mainAudioPlayer").attr("src", playbackURL);
|
|
startPlaybackAfterAudioLoaded(audio, playAfterLoad);
|
|
startPlaybackAfterAudioLoaded(audio, playAfterLoad);
|
|
|
|
|
|
- if (ext == "mp3"){
|
|
|
|
|
|
+ //Only cache non video audio tracks
|
|
|
|
+ if (ext == "mp3" || ext == "flac" || ext == "aac" || ext == "wav" || ext == "ogg"){
|
|
loadAudioFileURLAsBlob(playbackURL, function(fileBlob){
|
|
loadAudioFileURLAsBlob(playbackURL, function(fileBlob){
|
|
//Store the blob into indexDB
|
|
//Store the blob into indexDB
|
|
let cacheDbTx2 = cacheDb.transaction("files","readwrite");
|
|
let cacheDbTx2 = cacheDb.transaction("files","readwrite");
|
|
@@ -2299,7 +2300,42 @@
|
|
clearReq.onsuccess = function(e){
|
|
clearReq.onsuccess = function(e){
|
|
console.log("All cache file cleared");
|
|
console.log("All cache file cleared");
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function removeCacheByFilename(filename, callback=undefined){
|
|
|
|
+ let dbtx = cacheDb.transaction("files","readwrite");
|
|
|
|
+ let fstore = dbtx.objectStore("files");
|
|
|
|
+ let resp = fstore.delete(filename);
|
|
|
|
+ resp.onsuccess = function(evt){
|
|
|
|
+ if (callback != undefined){
|
|
|
|
+ callback(evt);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Clear all expired cache
|
|
|
|
+ function clearExpiredCache(){
|
|
|
|
+ var expireTime = 604800; //1 week
|
|
|
|
|
|
|
|
+ getAllItems(function(allCachedTracks){
|
|
|
|
+ var expiredFilenames = [];
|
|
|
|
+
|
|
|
|
+ //Check all the cache to see which is expired
|
|
|
|
+ allCachedTracks.forEach(function(track){
|
|
|
|
+ if (track.cachetime + expireTime < Date.now()/1000){
|
|
|
|
+ //Expired. Clear this cache
|
|
|
|
+ expiredFilenames.push(track.filename);
|
|
|
|
+ console.log("Expired track cleared: ", track);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //Delete those cache that have expired
|
|
|
|
+ expiredFilenames.forEach(function(filenameToBeDeleted){
|
|
|
|
+ removeCacheByFilename(filenameToBeDeleted);
|
|
|
|
+ })l
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
function getAllItems(callback) {
|
|
function getAllItems(callback) {
|
|
@@ -2726,6 +2762,9 @@
|
|
}
|
|
}
|
|
window.addEventListener('popstate', handleBackButton);
|
|
window.addEventListener('popstate', handleBackButton);
|
|
window.history.pushState({}, '');
|
|
window.history.pushState({}, '');
|
|
|
|
+
|
|
|
|
+ //Clear expired cache
|
|
|
|
+ clearExpiredCache();
|
|
</script>
|
|
</script>
|
|
</body>
|
|
</body>
|
|
</html>
|
|
</html>
|