index.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <!doctype html>
  2. <head>
  3. <title>Using multiple file formats in JavaScript</title>
  4. <script type= "text/javascript">
  5. function checkAudioCompat() {
  6. var myAudio = document.createElement('audio');
  7. var msg = document.getElementById("display");
  8. msg.innerHTML = "";
  9. if (myAudio.canPlayType) {
  10. // CanPlayType returns maybe, probably, or an empty string.
  11. var playMsg = myAudio.canPlayType('audio/mpeg');
  12. if ( "" != playMsg) {
  13. msg.innerHTML += "mp3 is " + playMsg + " supported<br/>";
  14. }
  15. playMsg = myAudio.canPlayType('audio/ogg; codecs="vorbis"');
  16. if ( "" != playMsg){
  17. msg.innerHTML += "ogg is " + playMsg + " supported<br/>";
  18. }
  19. playMsg = myAudio.canPlayType('audio/mp4; codecs="mp4a.40.5"');
  20. if ( "" != playMsg){
  21. msg.innerHTML += "aac is "+playMsg+" supported<br/>";
  22. }
  23. }
  24. else {
  25. msg.innerHTML += "no audio support";
  26. }
  27. }
  28. </script>
  29. </head>
  30. <body>
  31. <button onclick="checkAudioCompat();">
  32. Test for audio format type
  33. </button>
  34. <div id="display"> </div>
  35. <audio src="./1.aac" controls></audio>
  36. </body>
  37. </html>