HowToUse_Dll.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>MediaInfo JavaScript test page</title>
  5. </head>
  6. <body>
  7. <p>
  8. <input type="file" id="input" />
  9. </p>
  10. <p><pre id="result"></pre></p>
  11. <script type="text/javascript">
  12. // Load the WebAssembly MediaInfo module if the browser supports it,
  13. // otherwise load the asmjs module
  14. var MediaInfoJs = document.createElement('script');
  15. if ('WebAssembly' in window) {
  16. MediaInfoJs.src = "MediaInfoWasm.js";
  17. } else {
  18. MediaInfoJs.src = "MediaInfo.js";
  19. }
  20. document.body.appendChild(MediaInfoJs);
  21. // Continue initialization
  22. MediaInfoJs.onload = function () {
  23. var MediaInfoModule, MI, processing = false, CHUNK_SIZE = 1024 * 1024;
  24. var finish = function() {
  25. MI.Close();
  26. MI.delete();
  27. processing = false;
  28. }
  29. // Examples about how to get results
  30. var showResult = function() {
  31. document.getElementById('result').innerText = 'Inform with Complete=false:\n';
  32. MI.Option('Complete');
  33. document.getElementById('result').innerText += MI.Inform();
  34. document.getElementById('result').innerText += 'Inform with Complete=true:\n';
  35. MI.Option('Complete', '1');
  36. document.getElementById('result').innerText += MI.Inform();
  37. document.getElementById('result').innerText += 'Custom Inform:\n';
  38. MI.Option('Inform', 'General;Example: FileSize=%FileSize%')
  39. document.getElementById('result').innerText += MI.Inform() + '\n\n';
  40. MI.Option('Inform'); // Reset custom output
  41. document.getElementById('result').innerText += 'Get with Stream=General and Parameter=\'FileSize\':\n';
  42. document.getElementById('result').innerText += MI.Get(MediaInfoModule.Stream.General, 0, 'FileSize') + '\n\n';
  43. document.getElementById('result').innerText += 'GetI with Stream=General, Parameter=2, and InfoKind=Name:\n';
  44. document.getElementById('result').innerText += MI.GetI(MediaInfoModule.Stream.General, 0, 2, MediaInfoModule.Info.Name) + '\n\n';
  45. document.getElementById('result').innerText += 'GetI with Stream=General, Parameter=2, and InfoKind=Text:\n';
  46. document.getElementById('result').innerText += MI.GetI(MediaInfoModule.Stream.General, 0, 2) + '\n\n';
  47. document.getElementById('result').innerText += 'Count_Get with StreamKind=Audio:\n';
  48. document.getElementById('result').innerText += MI.Count_Get(MediaInfoModule.Stream.Audio) + '\n\n';
  49. document.getElementById('result').innerText += 'Get with Stream=General and Parameter=\'AudioCount\':\n';
  50. document.getElementById('result').innerText += MI.Get(MediaInfoModule.Stream.General, 0, 'AudioCount') + '\n\n';
  51. document.getElementById('result').innerText += 'Get with Stream=Audio and Parameter=\'StreamCount\':\n';
  52. document.getElementById('result').innerText += MI.Get(MediaInfoModule.Stream.Audio, 0, 'StreamCount') + '\n';
  53. finish();
  54. }
  55. var parseFile = function(file, callback) {
  56. if (processing) {
  57. return;
  58. }
  59. processing = true;
  60. var offset = 0;
  61. // Initialise MediaInfo
  62. MI = new MediaInfoModule.MediaInfo();
  63. //Open the file
  64. MI.Open(file, callback);
  65. /* By buffer example:
  66. MI.Option('File_FileName', file.name);
  67. MI.Open_Buffer_Init(file.size, 0);
  68. var loop = function(length) {
  69. if (processing) {
  70. var r = new FileReader();
  71. var blob = file.slice(offset, offset + length);
  72. r.onload = processChunk;
  73. r.readAsArrayBuffer(blob);
  74. } else {
  75. finish()
  76. }
  77. };
  78. var processChunk = function(e) {
  79. if (e.target.error === null) {
  80. // Send the buffer to MediaInfo
  81. var state = MI.Open_Buffer_Continue(e.target.result);
  82. //Test if there is a MediaInfo request to go elsewhere
  83. var seekTo = MI.Open_Buffer_Continue_Goto_Get();
  84. if(seekTo === -1) {
  85. offset += e.target.result.byteLength;
  86. } else {
  87. offset = seekTo;
  88. MI.Open_Buffer_Init(file.size, seekTo); // Inform MediaInfo we have seek
  89. }
  90. } else {
  91. finish();
  92. alert('An error happened reading your file!');
  93. return;
  94. }
  95. // Bit 3 set means finalized
  96. if (state&0x08 || e.target.result.byteLength < 1) {
  97. MI.Open_Buffer_Finalize();
  98. callback();
  99. return;
  100. }
  101. loop(CHUNK_SIZE);
  102. };
  103. // Start
  104. loop(CHUNK_SIZE);*/
  105. }
  106. // Initialise emscripten module
  107. MediaInfoModule = MediaInfoLib({'postRun': function() {
  108. console.debug('MediaInfo ready');
  109. // Information about MediaInfo
  110. document.getElementById('result').innerText = 'Info_Parameters:\n';
  111. document.getElementById('result').innerText += MediaInfoModule.MediaInfo.Option_Static('Info_Parameters') + '\n\n';
  112. document.getElementById('result').innerText += 'Info_Codecs:\n';
  113. document.getElementById('result').innerText += MediaInfoModule.MediaInfo.Option_Static('Info_Codecs') + '\n';
  114. // Get selected file
  115. var input = document.getElementById('input');
  116. input.onchange = function() {
  117. if(input.files.length > 0) {
  118. document.getElementById('result').innerText = "Processing...";
  119. parseFile(input.files[0], showResult);
  120. }
  121. }
  122. }});};
  123. </script>
  124. </body>
  125. </html>