| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>media-source-audio-track-id-switch</title> |
| <script src="media-source-loader.js"></script> |
| <script src="../video-test.js"></script> |
| <script> |
| var loader; |
| var source; |
| var sourceBuffer; |
| var audio; |
| |
| function runTest() { |
| audio = document.getElementsByTagName('audio')[0]; |
| |
| loader = new MediaSourceLoader('content/test-48khz-manifest.json'); |
| loader.onload = mediaDataLoaded; |
| loader.onerror = mediaDataLoadingFailed; |
| } |
| |
| function mediaDataLoadingFailed() { |
| failTest('Media data loading failed'); |
| } |
| |
| function mediaDataLoaded() { |
| source = new MediaSource(); |
| waitForEvent('sourceopen', sourceOpen, false, false, source); |
| run('audio.src = URL.createObjectURL(source)'); |
| } |
| |
| function sourceOpen() { |
| run('source.duration = loader.duration()'); |
| run('sourceBuffer = source.addSourceBuffer(loader.type())'); |
| sourceBuffer.addEventListener('error', mediaDataLoadingFailed); |
| waitForEventOn(sourceBuffer, 'updateend', sourceInitialized, false, true); |
| run('sourceBuffer.appendBuffer(loader.initSegment())'); |
| } |
| |
| function sourceInitialized() { |
| consoleWrite('Switching to a similar audio stream but with different mp4 track ID.') |
| loader = new MediaSourceLoader('content/test-48khz-new-track-id-manifest.json'); |
| loader.onload = newTrackMediaDataLoaded; |
| loader.onerror = mediaDataLoadingFailed; |
| } |
| |
| function newTrackMediaDataLoaded() { |
| waitForEventOn(sourceBuffer, 'updateend', endTest, false, true); |
| run('sourceBuffer.appendBuffer(loader.initSegment())'); |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <audio controls/> |
| </body> |
| </html> |