1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webaudio/test/test_decodeMultichannel.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<meta charset=utf-8> 1.7 +<head> 1.8 + <title>Test that we can decode 4 channel wave file in webaudio, but not in <audio></title> 1.9 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +<pre id="test"> 1.14 +<script class="testbody" type="text/javascript"> 1.15 +var filename = "audio-quad.wav"; 1.16 + 1.17 +SimpleTest.waitForExplicitFinish(); 1.18 + 1.19 +function finishTest(a) { 1.20 + if (a) { 1.21 + a = null; 1.22 + SimpleTest.finish(); 1.23 + } 1.24 +} 1.25 + 1.26 +function decodeUsingAudioElement() { 1.27 + var a = new Audio(); 1.28 + a.addEventListener("error", function() { 1.29 + ok(true, "We should not be able to decode this file using an HTMLAudioElement"); 1.30 + finishTest(a); 1.31 + }); 1.32 + a.addEventListener("loadedmetadata", function() { 1.33 + ok(false, "We should not be able to decode this file using an HTMLMediaElement."); 1.34 + finishTest(a); 1.35 + }); 1.36 + 1.37 + a.src = filename; 1.38 + a.load(); 1.39 +} 1.40 + 1.41 +addLoadEvent(function() { 1.42 + var xhr = new XMLHttpRequest(); 1.43 + xhr.open("GET", filename); 1.44 + xhr.responseType = "arraybuffer"; 1.45 + xhr.onload = function() { 1.46 + var context = new AudioContext(); 1.47 + context.decodeAudioData(xhr.response, function(b) { 1.48 + ok(true, "Decoding of a wave file with four channels succeded."); 1.49 + is(b.numberOfChannels, 4, "The AudioBuffer should have 4 channels."); 1.50 + decodeUsingAudioElement(); 1.51 + }, function() { 1.52 + ok(false, "Decoding of a wave file with four channels failed."); 1.53 + decodeUsingAudioElement(); 1.54 + }); 1.55 + }; 1.56 + xhr.send(null); 1.57 +}); 1.58 +</script> 1.59 +</pre> 1.60 +</body> 1.61 +</html>