Permalink
Browse files

Added check for browser audio type

  • Loading branch information...
1 parent bc43b6a commit ea36350dcae5d8d2d80b019675008c6df6db3526 Tony Camp committed Jan 20, 2011
Showing with 19 additions and 7 deletions.
  1. 0 README.markdown
  2. 0 css/main.css
  3. +1 −4 index.html
  4. +18 −3 js/mediaChapters.js
View
0 README.markdown 100644 → 100755
No changes.
View
0 css/main.css 100644 → 100755
No changes.
View
5 index.html 100644 → 100755
@@ -6,10 +6,7 @@
<link rel="stylesheet" href="css/main.css" type="text/css" media="screen">
</head>
<body>
- <audio class="myaudio" controls>
- <source src=""></source>
- <source src=""></source>
- </audio>
+ <audio class="myaudio" controls></audio>
<ul id="episodes">
<li>
<span class="episode_title" data-filename="yayquery_0">Episode 0</span>
View
21 js/mediaChapters.js 100644 → 100755
@@ -6,8 +6,23 @@
var mediaChapters = {
audioElement: $('.audio'), // Default audio player that will load the audio file
audioChapter: $('.loader'), // Default element that will have the data-timestamp for the chapter
- audioDirectory: 'mp3' // Directory where audio files live
- };
+ audioDirectory: 'mp3', // Directory where audio files live
+ },
+ bool = !!mediaChapters.audioElement.canPlayType;
+
+ // Modernizr's audio file compatibility check
+ // http://www.modernizr.com/
+ if (bool){
+ bool = new Boolean(bool);
+ bool.ogg = elem.canPlayType('audio/ogg; codecs="vorbis"');
+ bool.mp3 = elem.canPlayType('audio/mpeg;');
+ }
+
+ if(bool.mp3) {
+ var extension = '.mp3';
+ } else {
+ var extension = '.ogg';
+ }
if(options) {
$.extend(mediaChapters, options);
@@ -21,7 +36,7 @@
$.ajax({
success: function() {
mediaChapters.audioElement.attr({
- src: mediaChapters.audioDirectory + '/' + episode + '.mp3'
+ src: mediaChapters.audioDirectory + '/' + episode + extension
});
}
});

0 comments on commit ea36350

Please sign in to comment.