diff options
author | ente <ente@baer.rwth-aachen.de> | 2010-12-05 17:51:10 +0100 |
---|---|---|
committer | ente <ente@baer.rwth-aachen.de> | 2010-12-05 17:51:10 +0100 |
commit | 7e83db10d55334da9981d2fa2958d03902bf0b47 (patch) | |
tree | 26bd60cabf5275b753a739bc70ae1076fd9183d3 | |
parent | db5cac3b3fa64af74353ae121e75d2182a211327 (diff) | |
download | nextcloud-server-7e83db10d55334da9981d2fa2958d03902bf0b47.tar.gz nextcloud-server-7e83db10d55334da9981d2fa2958d03902bf0b47.zip |
Only register the "Play" action for audio types that the browser is able to play.
Otherwise just leave the default action to "Download".
-rw-r--r-- | plugins/audioplayer/audioplayer.js | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/plugins/audioplayer/audioplayer.js b/plugins/audioplayer/audioplayer.js index c58058b5696..2cf4133d818 100644 --- a/plugins/audioplayer/audioplayer.js +++ b/plugins/audioplayer/audioplayer.js @@ -11,12 +11,12 @@ OC_AudioPlayer.playAudio = function(dir, file, type) { var audio = document.createElement('audio'); var source = document.createElement('source'); - if (!(!!(audio.canPlayType) && (audio.canPlayType(type) != "no") && (audio.canPlayType(type) != ""))) { - // use a flash player fallback - // or implement some nice on-the-fly recoding here - alert("Native playing of '"+type+"' format is not supported by your browser."); - return; - } +// if (!(!!(audio.canPlayType) && (audio.canPlayType(type) != "no") && (audio.canPlayType(type) != ""))) { +// // use a flash player fallback +// // or implement some nice on-the-fly recoding here +// alert("Native playing of '"+type+"' format is not supported by your browser."); +// return; +// } audio.setAttribute('controls', 'true'); audio.setAttribute('preload', 'auto'); audio.setAttribute('autoplay', 'true'); @@ -41,20 +41,26 @@ OC_AudioPlayer.hidePlayer = function(){ div.parentNode.removeChild(div); } - -if(!OC_FILES.fileActions.audio){ - OC_FILES.fileActions.audio = new Object(); -} -if(!OC_FILES.fileActions.applicationogg){ - OC_FILES.fileActions.applicationogg = new Object(); -} - -OC_FILES.fileActions.audio.play = function() { - OC_AudioPlayer.playAudio(this.dir, this.file, this.mime); -} -OC_FILES.fileActions.applicationogg.play = function() { - OC_AudioPlayer.playAudio(this.dir, this.file, this.mime); +// only register "play" option for file formats the browser claims to support +OC_AudioPlayer.formats = { + 'audio/mpeg':"mp3", + 'audio/ogg':"ogg", + 'application/ogg':"ogg", + 'audio/wav':"wav", + 'audio/wave':"wav", + 'audio/x-wav':"wav", + 'audio/basic':"au", + 'audio/x-aiff':"aif" +}; +var audio = document.createElement('audio'); +for(format in OC_AudioPlayer.formats) { + if (!!(audio.canPlayType) && (audio.canPlayType(format) != "no") && (audio.canPlayType(format) != "")) { + if(!OC_FILES.fileActions[format]) { + OC_FILES.fileActions[format] = new Object(); + } + OC_FILES.fileActions[format].play = function() { + OC_AudioPlayer.playAudio(this.dir, this.file, this.mime); + } + OC_FILES.fileActions[format]['default'] = OC_FILES.fileActions[format].play; + } } - -OC_FILES.fileActions.audio['default'] = OC_FILES.fileActions.audio.play; -OC_FILES.fileActions.applicationogg['default'] = OC_FILES.fileActions.applicationogg.play; |