summaryrefslogtreecommitdiffstats
path: root/apps/media/js/files.js
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2011-07-26 16:04:57 +0200
committerRobin Appelman <icewind1991@gmail.com>2011-07-26 16:05:24 +0200
commit0e05a8648404d48fb974bb069e1b465219165a44 (patch)
tree9c03874b35b81acaf0cb3db77a6c3001924dd019 /apps/media/js/files.js
parent243199859b6e1f1d85be7f7c1c0ec38cccaef2f6 (diff)
downloadnextcloud-server-0e05a8648404d48fb974bb069e1b465219165a44.tar.gz
nextcloud-server-0e05a8648404d48fb974bb069e1b465219165a44.zip
some refactoring of the media player code
Diffstat (limited to 'apps/media/js/files.js')
-rw-r--r--apps/media/js/files.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/apps/media/js/files.js b/apps/media/js/files.js
new file mode 100644
index 00000000000..d699a96db7e
--- /dev/null
+++ b/apps/media/js/files.js
@@ -0,0 +1,50 @@
+function musicTypeFromFile(file){
+ var extention=file.substr(file.indexOf('.')+1);
+ if(extention=='ogg'){
+ return 'oga'
+ }
+ //TODO check for more specific cases
+ return extention;
+}
+
+function playAudio(filename){
+ loadPlayer(musicTypeFromFile(filename),function(){
+ PlayList.add($('#dir').val()+'/'+filename);
+ PlayList.play(PlayList.items.length-1);
+ });
+}
+
+function addAudio(filename){
+ loadPlayer(musicTypeFromFile(filename),function(){
+ PlayList.add($('#dir').val()+'/'+filename);
+ });
+}
+
+function loadPlayer(type,ready){
+ if(!loadPlayer.done){
+ OC.addScript('media','jquery.jplayer.min',function(){
+ OC.addScript('media','player',function(){
+ $('body').append($('<div id="playerPlaceholder"/>'))
+ $('#playerPlaceholder').append($('<div/>')).load(OC.filePath('media','templates','player.php'),function(){
+ loadPlayer.done=true;
+ PlayList.init(type,ready);
+ });
+ });
+ });
+ OC.addStyle('media','player');
+ }else{
+ ready();
+ }
+}
+
+$(document).ready(function() {
+ loadPlayer.done=false
+
+ FileActions.register('audio','Add to playlist',addAudio);
+ FileActions.register('application/ogg','Add to playlist',addAudio);
+
+ FileActions.register('audio','Play',playAudio);
+ FileActions.register('application/ogg','Play',playAudio);
+ FileActions.setDefault('audio','Play');
+ FileActions.setDefault('application/ogg','Play');
+}); \ No newline at end of file