common.js 901 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. Common.js
  3. This file includes all the common functions required by other script files
  4. To use this, include this script file at the top of the other script file
  5. e.g.
  6. var succ = includes("common.js");
  7. */
  8. //Check if the given extension is supported in AirMusic
  9. function IsSupportExt(ext){
  10. var supportExtList = [".mp3",".flac",".wav",".ogg",".aac",".webm"];
  11. ext = "." + ext;
  12. for (var i = 0; i < supportExtList.length; i++){
  13. var thisExt = supportExtList[i];
  14. if (ext == thisExt){
  15. return true
  16. }
  17. }
  18. return false
  19. }
  20. //Convert filesize from bytes to human readable format
  21. function bytesToSize(bytes) {
  22. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  23. if (bytes == 0) return '0 Byte';
  24. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  25. return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i];
  26. }