yading@9
|
1 <!DOCTYPE html>
|
yading@9
|
2 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="application/javascript"></script>
|
yading@9
|
3 <script type="application/javascript">
|
yading@9
|
4
|
yading@9
|
5 var accessId = 'bc59492a-d127-487b-acb4-c2e4226b34cb';
|
yading@9
|
6 var taskUrl = 'process/elastique';
|
yading@9
|
7 var parameters = { blocking: false, format: 'json', access_id: accessId };
|
yading@9
|
8
|
yading@9
|
9 // the values for these parameters were taken from the corresponding controls in the demo form
|
yading@9
|
10 parameters['input_file'] = 'Wake_Me_Up_When September_Ends.mp3';
|
yading@9
|
11 parameters['pitch_semitones'] = '0';
|
yading@9
|
12 parameters['tempo_factor'] = '2';
|
yading@9
|
13 parameters['formant_semitones'] = '0';
|
yading@9
|
14
|
yading@9
|
15 function onTaskStarted(data) {
|
yading@9
|
16 var fileId = data.file.file_id;
|
yading@9
|
17
|
yading@9
|
18 // request task progress every 500ms
|
yading@9
|
19 var polling = setInterval(pollTaskProgress, 500);
|
yading@9
|
20
|
yading@9
|
21 function pollTaskProgress() {
|
yading@9
|
22 $.ajax({ url: 'https://api.sonicAPI.com/file/status?file_id=' + fileId + '&access_id=' + accessId + '&format=json',
|
yading@9
|
23 crossDomain: true, success: function(data) {
|
yading@9
|
24 if (data.file.status == 'ready') {
|
yading@9
|
25 onTaskSucceeded(fileId);
|
yading@9
|
26 clearInterval(polling);
|
yading@9
|
27 } else if (data.file.status == 'working') {
|
yading@9
|
28 $('#result').text(data.file.progress + '% done');
|
yading@9
|
29 }
|
yading@9
|
30 }});
|
yading@9
|
31 }
|
yading@9
|
32 }
|
yading@9
|
33
|
yading@9
|
34 function onTaskSucceeded(fileId) {
|
yading@9
|
35 // create HTML5 audio player
|
yading@9
|
36 var downloadUrl = 'https://api.sonicAPI.com/file/download?file_id=' + fileId + '&access_id=' + accessId + '&format=mp3-cbr';
|
yading@9
|
37 var audio = '<audio src="' + downloadUrl + '" controls="controls" autoplay="autoplay">';
|
yading@9
|
38
|
yading@9
|
39 $('#result').html(audio);
|
yading@9
|
40 }
|
yading@9
|
41
|
yading@9
|
42 function onTaskFailed(response) {
|
yading@9
|
43 var data = $.parseJSON(response.responseText);
|
yading@9
|
44 var errorMessages = data.errors.map(function(error) { return error.message; });
|
yading@9
|
45
|
yading@9
|
46 $('#result').text('Task failed, reason: ' + errorMessages.join(','));
|
yading@9
|
47 }
|
yading@9
|
48
|
yading@9
|
49 // start task when clicking on the "Start task" button
|
yading@9
|
50 $(document).ready(function() {
|
yading@9
|
51 $('#start').click(function() {
|
yading@9
|
52 // execute an HTTP GET using the task's URL, the parameters and callback functions defined above
|
yading@9
|
53 $.ajax({ url: 'https://api.sonicAPI.com/' + taskUrl, data: parameters,
|
yading@9
|
54 success: onTaskStarted, error: onTaskFailed, crossDomain: true });
|
yading@9
|
55 });
|
yading@9
|
56 });
|
yading@9
|
57 </script>
|
yading@9
|
58 <input type="button" id="start" value="Start task" />
|
yading@9
|
59 <div id="result" /> |