music.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. $(document).ready(function(){
  2. OC.search.customResults.Music=function(row,item){
  3. var parts=item.link.substr(item.link.indexOf('#')+1).split('&');
  4. var data={};
  5. for(var i=0;i<parts.length;i++){
  6. var itemParts=parts[i].split('=');
  7. data[itemParts[0]]=itemParts[1].replace(/\+/g,' ');
  8. }
  9. var media=Collection.find(data.artist,data.album,data.song);
  10. var a=row.find('a');
  11. a.attr('href','#');
  12. a.click(function(){
  13. var oldSize=PlayList.items.length;
  14. PlayList.add(media);
  15. PlayList.play(oldSize);
  16. PlayList.render();
  17. });
  18. var button=$('<input type="button" title="'+t('media','Add album to playlist')+'" class="add"></input>');
  19. button.css('background-image','url('+OC.imagePath('core','actions/play-add')+')');
  20. button.click(function(event){
  21. event.stopPropagation();
  22. PlayList.add(media);
  23. PlayList.render();
  24. });
  25. row.find('div.name').append(button);
  26. button.tipsy({gravity:'n', fade:true, delayIn: 400, live:true});
  27. };
  28. Collection.display();
  29. Collection.load(function(){
  30. var urlVars=getUrlVars();
  31. if(urlVars.artist){
  32. var song=Collection.find(urlVars.artist,urlVars.album,urlVars.song);
  33. PlayList.add(song);
  34. PlayList.play(0);
  35. }
  36. });
  37. });
  38. function getUrlVars(){
  39. var vars = {}, hash;
  40. var hashes = window.location.hash.substr(1).split('&');
  41. for(var i = 0; i < hashes.length; i++){
  42. hash = hashes[i].split('=');
  43. vars[hash[0]] = decodeURIComponent(hash[1]).replace(/\+/g,' ');
  44. }
  45. return vars;
  46. }
  47. function musicTypeFromFile(file){
  48. var extension=file.split('.').pop().toLowerCase();
  49. if(extension=='ogg'){
  50. return 'oga';
  51. }
  52. //TODO check for more specific cases
  53. return extension;
  54. }