File: HowToUse_Dll.html

package info (click to toggle)
libmediainfo 20.09%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 17,296 kB
  • sloc: cpp: 205,411; ansic: 5,215; asm: 2,081; xml: 1,476; sh: 1,062; java: 1,032; cs: 944; python: 653; makefile: 383; pascal: 197; javascript: 188
file content (153 lines) | stat: -rw-r--r-- 6,713 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!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>