| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>MediaInfo JavaScript test page</title>
- </head>
- <body>
- <p>
- <input type="file" id="input" />
- </p>
- <p><pre id="result"></pre></p>
- <script type="text/javascript">
- // Load the WebAssembly MediaInfo module if the browser supports it,
- // otherwise load the asmjs module
- var MediaInfoJs = document.createElement('script');
- if ('WebAssembly' in window) {
- MediaInfoJs.src = "MediaInfoWasm.js";
- } else {
- MediaInfoJs.src = "MediaInfo.js";
- }
- document.body.appendChild(MediaInfoJs);
- // Continue initialization
- MediaInfoJs.onload = function () {
- var MediaInfoModule, MI, processing = false, CHUNK_SIZE = 1024 * 1024;
- var finish = function() {
- MI.Close();
- MI.delete();
- processing = false;
- }
- // Examples about how to get results
- var showResult = function() {
- document.getElementById('result').innerText = 'Inform with Complete=false:\n';
- MI.Option('Complete');
- document.getElementById('result').innerText += MI.Inform();
- document.getElementById('result').innerText += 'Inform with Complete=true:\n';
- MI.Option('Complete', '1');
- document.getElementById('result').innerText += MI.Inform();
- document.getElementById('result').innerText += 'Custom Inform:\n';
- MI.Option('Inform', 'General;Example: FileSize=%FileSize%')
- document.getElementById('result').innerText += MI.Inform() + '\n\n';
- MI.Option('Inform'); // Reset custom output
- document.getElementById('result').innerText += 'Get with Stream=General and Parameter=\'FileSize\':\n';
- document.getElementById('result').innerText += MI.Get(MediaInfoModule.Stream.General, 0, 'FileSize') + '\n\n';
- document.getElementById('result').innerText += 'GetI with Stream=General, Parameter=2, and InfoKind=Name:\n';
- document.getElementById('result').innerText += MI.GetI(MediaInfoModule.Stream.General, 0, 2, MediaInfoModule.Info.Name) + '\n\n';
- document.getElementById('result').innerText += 'GetI with Stream=General, Parameter=2, and InfoKind=Text:\n';
- document.getElementById('result').innerText += MI.GetI(MediaInfoModule.Stream.General, 0, 2) + '\n\n';
- document.getElementById('result').innerText += 'Count_Get with StreamKind=Audio:\n';
- document.getElementById('result').innerText += MI.Count_Get(MediaInfoModule.Stream.Audio) + '\n\n';
- document.getElementById('result').innerText += 'Get with Stream=General and Parameter=\'AudioCount\':\n';
- document.getElementById('result').innerText += MI.Get(MediaInfoModule.Stream.General, 0, 'AudioCount') + '\n\n';
- document.getElementById('result').innerText += 'Get with Stream=Audio and Parameter=\'StreamCount\':\n';
- document.getElementById('result').innerText += MI.Get(MediaInfoModule.Stream.Audio, 0, 'StreamCount') + '\n';
- finish();
- }
- var parseFile = function(file, callback) {
- if (processing) {
- return;
- }
- processing = true;
- var offset = 0;
- // Initialise MediaInfo
- MI = new MediaInfoModule.MediaInfo();
- //Open the file
- MI.Open(file, callback);
- /* By buffer example:
- MI.Option('File_FileName', file.name);
- MI.Open_Buffer_Init(file.size, 0);
- var loop = function(length) {
- if (processing) {
- var r = new FileReader();
- var blob = file.slice(offset, offset + length);
- r.onload = processChunk;
- r.readAsArrayBuffer(blob);
- } else {
- finish()
- }
- };
- var processChunk = function(e) {
- if (e.target.error === null) {
- // Send the buffer to MediaInfo
- var state = MI.Open_Buffer_Continue(e.target.result);
- //Test if there is a MediaInfo request to go elsewhere
- var seekTo = MI.Open_Buffer_Continue_Goto_Get();
- if(seekTo === -1) {
- offset += e.target.result.byteLength;
- } else {
- offset = seekTo;
- MI.Open_Buffer_Init(file.size, seekTo); // Inform MediaInfo we have seek
- }
- } else {
- finish();
- alert('An error happened reading your file!');
- return;
- }
- // Bit 3 set means finalized
- if (state&0x08 || e.target.result.byteLength < 1) {
- MI.Open_Buffer_Finalize();
- callback();
- return;
- }
- loop(CHUNK_SIZE);
- };
- // Start
- loop(CHUNK_SIZE);*/
- }
- // Initialise emscripten module
- MediaInfoModule = MediaInfoLib({'postRun': function() {
- console.debug('MediaInfo ready');
- // Information about MediaInfo
- document.getElementById('result').innerText = 'Info_Parameters:\n';
- document.getElementById('result').innerText += MediaInfoModule.MediaInfo.Option_Static('Info_Parameters') + '\n\n';
- document.getElementById('result').innerText += 'Info_Codecs:\n';
- document.getElementById('result').innerText += MediaInfoModule.MediaInfo.Option_Static('Info_Codecs') + '\n';
- // Get selected file
- var input = document.getElementById('input');
- input.onchange = function() {
- if(input.files.length > 0) {
- document.getElementById('result').innerText = "Processing...";
- parseFile(input.files[0], showResult);
- }
- }
- }});};
- </script>
- </body>
- </html>
|