-
Notifications
You must be signed in to change notification settings - Fork 12
/
iframe.html
140 lines (128 loc) · 4.44 KB
/
iframe.html
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
<!DOCTYPE html>
<html>
<head>
<title>FLAC Encoder</title>
<meta charset="UTF-8">
<script src="jquery.min.js"></script>
</head>
<!--
/*!
* Copyright © 2014 Rainer Rillke <lastname>@wikipedia.de
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
-->
<body>
<div id="body-content">
<h1>FLAC Encoder</h1>
<progress style="display: inline-block; text-align: center; width: 100%;" value="0" max="100">Your browser does not support this tool. Upgrade to a modern browser, please.</progress>
<input id="com-file-analyzer-fileinput" autofocus="" type="file" />
<script type='text/javascript'>
var $prog = $('progress'),
$console = $('#console'),
$input = $('input'),
// Create a new web worker
// note that for each file you're going to encode
// you'll need to create a new web worker even
// if the previous one already finished
// This is because the "runtime" is shut down by
// Emscripten after one file was encoded
worker = new Worker('worker/EmsWorkerProxy.js');
// $input is a file input
// when its value changed, the user most likely
// inserted a file
$input.change(function() {
// Get the file supplied by the user
// and create a FileReader to get its
// contents as ArrayBuffer
var f = this.files[0],
fr = new FileReader();
// Disable input to prevent the user
// from inserting another file
$input.attr('disabled', 'disabled');
// Add an event listener to the file reader
// so we know when it's done with the whole file
fr.addEventListener('loadend', function() {
var encodedName = f.name.replace(/\.[^\.]+$/, '.flac');
// Command line arguments
// These are strings such as
// options, input file and output file
var args = [
// Input file *name*
f.name
];
// Input file data
// Object literal mapping
// file names to Uint8Array
var inData = {};
// Remember: We set f.name as input file name
inData[f.name] = new Uint8Array(fr.result);
// Meta-information about the files
// that are being created during encoding
// Currently MIME type only
var outData = {};
outData[encodedName] = {
// Its MIME type
'MIME': 'audio/flac'
};
// Finally post all the data to the
// worker together with the "encode"
// command.
worker.postMessage({
command: 'encode',
args: args,
outData: outData,
fileData: inData
});
});
// Read the file as ArrayBuffer
// The FileReader will fire the `loadend`
// event upon completion.
fr.readAsArrayBuffer(f);
});
// Listen for messages by the worker
worker.onmessage = function(e) {
// If the message is a progress message
if (e.data && e.data.reply === 'progress') {
vals = e.data.values;
if (vals[1]) {
// ... push the progress bar forward
$prog.val(vals[0] / vals[1] * 100);
}
// If the worker is ready
} else if (e.data && e.data.reply === 'done') {
$prog.val(100);
for (fileName in e.data.values) {
// ... offer all files the worker returned
// In this case it's only one because we didn't
// use a command line argument that would force
// flac.js to create another file
$('<a>')
.text(fileName)
.prop('href',
window.URL.createObjectURL(e.data.values[fileName].blob)
)
.insertAfter($input);
}
}
};
</script>
</div>
</body>
</html>