Skip to content

Commit

Permalink
Fixing audiojs to only display if audio is not supported by the brows…
Browse files Browse the repository at this point in the history
…er and do not show the HTML5 audio tags along with the swf if html5 is not supported
  • Loading branch information
carolyncole committed Feb 7, 2014
1 parent 5731333 commit d7e9f83
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
21 changes: 1 addition & 20 deletions app/assets/javascripts/sufia.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ limitations under the License.
//= require sufia/multiForm
//= require sufia/edit_metadata
//= require sufia/single_use_link
//= require sufia/audio
//= require hydra/batch_select
//= require hydra_collections

Expand Down Expand Up @@ -175,23 +176,3 @@ function preg_quote( str ) {

return (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
}


function initialize_audio() {

if (navigator.userAgent.match("Chrome")){
$('audio').each(function() {
this.controls = true;
});
}else {
$('audio').each(function() {
$(this).attr("preload","auto");
});
audiojs.events.ready(function() {
var as = audiojs.createAll({
imageLocation: '/assets/player-graphics.gif',
swfLocation: '/assets/audiojs.swf'
});
});
};
}
28 changes: 28 additions & 0 deletions app/assets/javascripts/sufia/audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function initialize_audio() {

var test_audio= document.createElement("audio") //try and create sample audio element
var audiosupport= (test_audio.play)? true : false

if (audiosupport){
$('audio').each(function() {
this.controls = true;
});
}else {
$('audio').each(function() {
$(this).attr("preload","auto");
});
audiojs.events.ready(function() {
var as = audiojs.createAll({
imageLocation: '/assets/player-graphics.gif',
swfLocation: '/assets/audiojs.swf'
});

// remove html 5 player from veiw on firefox and safari
$('.audiojs').addClass('no-audio-background')
$('.audiojs .play-pause').addClass('hide')
$('.audiojs .scrubber').addClass('hide')
$('.audiojs .time').addClass('hide')

});
};
}
9 changes: 9 additions & 0 deletions app/assets/stylesheets/sufia-audio-overrides.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

.no-audio-background {
background: none;
box-shadow: none;
}

.span40 .audiojs audio {
left: 10px;
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/sufia.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*= require audio-js
*= require dashboard
*= require jquery-ui
*= require sufia-audio-overrides
*/

@import 'font-awesome';

2 changes: 1 addition & 1 deletion app/views/generic_files/_media_display.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Your browser does not support the video tag.
</video>
<% elsif @generic_file.audio? %>
<audio controls="controls" class="video-js vjs-default-skin" data-setup="{}" preload="auto">
<audio controls="controls" class="audiojs" preload="auto">
<source src="<%= sufia.download_path(@generic_file, datastream_id: 'ogg') %>" type="audio/ogg" />
<source src="<%= sufia.download_path(@generic_file, datastream_id: 'mp3') %>" type="audio/mpeg" />
Your browser does not support the audio tag.
Expand Down

0 comments on commit d7e9f83

Please sign in to comment.