loader.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function musicTypeFromFile(file){
  2. var extension=file.substr(file.indexOf('.')+1).toLowerCase();
  3. if(extension=='ogg'){
  4. return 'oga';
  5. }
  6. //TODO check for more specific cases
  7. return extension;
  8. }
  9. function playAudio(filename){
  10. loadPlayer(musicTypeFromFile(filename),function(){
  11. PlayList.add($('#dir').val()+'/'+filename);
  12. PlayList.play(PlayList.items.length-1);
  13. });
  14. }
  15. function addAudio(filename){
  16. loadPlayer(musicTypeFromFile(filename),function(){
  17. PlayList.add($('#dir').val()+'/'+filename);
  18. });
  19. }
  20. function loadPlayer(type,ready){
  21. if(!loadPlayer.done){
  22. loadPlayer.done=true;
  23. OC.addStyle('media','player');
  24. OC.addScript('media','jquery.jplayer.min',function(){
  25. OC.addScript('media','player',function(){
  26. var navItem=$('#apps a[href="'+OC.linkTo('media','index.php')+'"]');
  27. navItem.height(navItem.height());
  28. navItem.load(OC.filePath('media','templates','player.php'),function(){
  29. PlayList.init(type,ready);
  30. });
  31. });
  32. });
  33. }else{
  34. ready();
  35. }
  36. }
  37. $(document).ready(function() {
  38. loadPlayer.done=false;
  39. // FileActions.register('audio','Add to playlist','',addAudio);
  40. // FileActions.register('application/ogg','Add to playlist','',addAudio);
  41. if(typeof FileActions!=='undefined'){
  42. FileActions.register('audio','Play','',playAudio);
  43. FileActions.register('application/ogg','','Play',playAudio);
  44. FileActions.setDefault('audio','Play');
  45. FileActions.setDefault('application/ogg','Play');
  46. }
  47. var oc_current_user=OC.currentUser;
  48. if(typeof PlayList==='undefined'){
  49. if(OC.localStorage.getItem('playlist_items') && OC.localStorage.getItem('playlist_items').length && OC.localStorage.getItem('playlist_active')!=true){
  50. loadPlayer();
  51. }
  52. }
  53. });