audio-recording: custom progress bar
This commit is contained in:
@@ -32,6 +32,7 @@ tr.inactive{
|
|||||||
height: 1rem;
|
height: 1rem;
|
||||||
border: 0;
|
border: 0;
|
||||||
box-shadow: #888 2px 2px 1px 1px;
|
box-shadow: #888 2px 2px 1px 1px;
|
||||||
|
transition : width 1s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
#content div.ok,
|
#content div.ok,
|
||||||
@@ -42,4 +43,30 @@ tr.inactive{
|
|||||||
margin: 1px;
|
margin: 1px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#progress_container{
|
||||||
|
display:flex;
|
||||||
|
box-shadow: #888 2px 2px 1px 1px;
|
||||||
|
width:100%;
|
||||||
|
padding:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#progress_container div{
|
||||||
|
transition : width 3s linear;
|
||||||
|
text-align: center;
|
||||||
|
padding: 1rem;
|
||||||
|
color:white;
|
||||||
|
overflow:none;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
#progress_container #progress_done{
|
||||||
|
background:#004f9b;
|
||||||
|
}
|
||||||
|
|
||||||
|
#progress_container #progress_todo{
|
||||||
|
color: #004f9b;
|
||||||
|
background:#ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,13 +45,19 @@ function hideFinished(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function roundSize(size){
|
function roundSize(size){
|
||||||
var MB=1000*1000;
|
const MB = 1000*1000;
|
||||||
var value= Math.round(size*10/MB)/10;
|
var value= Math.round(size/MB);
|
||||||
value+='';
|
value += '';
|
||||||
if (value.indexOf('.')<0)value+='.0';
|
//if (value.indexOf('.')<0)value+='.0';
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatTime(duration){
|
||||||
|
if (duration > 3600) return Math.ceil(duration/3600) + " hours";
|
||||||
|
if (duration > 60) return Math.ceil(duration/60) + " minutes";
|
||||||
|
return duration += " seconds";
|
||||||
|
}
|
||||||
|
|
||||||
function uploadFile(uploadButton){
|
function uploadFile(uploadButton){
|
||||||
hideFinished();
|
hideFinished();
|
||||||
hideError();
|
hideError();
|
||||||
@@ -64,39 +70,42 @@ function uploadFile(uploadButton){
|
|||||||
contentType: false,
|
contentType: false,
|
||||||
processData: false,
|
processData: false,
|
||||||
xhr: function() {
|
xhr: function() {
|
||||||
var start = new Date();
|
var start = Math.floor(Date.now()/1000);
|
||||||
|
var update = start;
|
||||||
var xhr = new window.XMLHttpRequest();
|
var xhr = new window.XMLHttpRequest();
|
||||||
|
$('#uploadButton').hide();
|
||||||
if (xhr.upload) {
|
if (xhr.upload) {
|
||||||
var c=0;
|
$('#progress_done').html(0);
|
||||||
var oldRemaining=0;
|
$('#progress_todo').html(100);
|
||||||
|
$('#progress_done').css("width", 0 + "%")
|
||||||
|
$('#progress_todo').css("width", (100)+ "%")
|
||||||
|
$('#progress_container').show();
|
||||||
|
|
||||||
xhr.upload.addEventListener(
|
xhr.upload.addEventListener(
|
||||||
'progress',
|
'progress',
|
||||||
function(data) {
|
function(data) {
|
||||||
if (!data.lengthComputable) return;
|
if (!data.lengthComputable) return;
|
||||||
c++;
|
let now = Math.floor(Date.now()/1000);
|
||||||
|
if (now == update) return;
|
||||||
|
update = now;
|
||||||
|
|
||||||
var loaded=roundSize(data.loaded);
|
let loaded = roundSize(data.loaded);
|
||||||
var total=roundSize(data.total);
|
if (loaded == 0) return;
|
||||||
$('#progressBar').attr("value", loaded);
|
let total = roundSize(data.total);
|
||||||
$('#progressBar').attr("max", total);
|
let duration = now - start;
|
||||||
|
if (duration == 0) return;
|
||||||
|
let remaining = Math.round( (duration * data.total / data.loaded) - duration );
|
||||||
|
remaining = formatTime(remaining);
|
||||||
|
duration = formatTime(duration);
|
||||||
|
|
||||||
|
var perc = Math.round(100*loaded/total);
|
||||||
|
$('#progress_done').css("width", perc + "%")
|
||||||
|
$('#progress_todo').css("width", (100-perc)+ "%")
|
||||||
|
$('#progress_done').html(loaded + " MB");
|
||||||
|
$('#progress_todo').html(remaining+" left");
|
||||||
|
|
||||||
if (c<2)return;
|
let content = total + " MB<br>";
|
||||||
c=0;
|
$('#progressLabel').html(content);
|
||||||
|
|
||||||
var duration=(new Date().getTime() - start.getTime()) / 1000 ;
|
|
||||||
var bitrate = loaded / duration;
|
|
||||||
|
|
||||||
var remaining = Math.round( (duration * data.total / data.loaded) - duration );
|
|
||||||
if (oldRemaining == 0) oldRemaining = remaining;
|
|
||||||
if (duration>30) remaining= oldRemaining*0.5 + remaining*0.5;
|
|
||||||
oldRemaining=remaining;
|
|
||||||
|
|
||||||
var content = loaded + " of " + total + " MB<br>";
|
|
||||||
content += '<div class="thin">';
|
|
||||||
content += "finished in " + Math.round(remaining) + " seconds<br>";
|
|
||||||
content += "took " + Math.round(duration) + " seconds<br>";
|
|
||||||
content += '</div>'
|
|
||||||
$('#progressLabel').html(content);
|
|
||||||
} ,
|
} ,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@@ -110,6 +119,7 @@ function uploadFile(uploadButton){
|
|||||||
showError("error: "+errorThrown);
|
showError("error: "+errorThrown);
|
||||||
hideProgress();
|
hideProgress();
|
||||||
hideFinished();
|
hideFinished();
|
||||||
|
$('#uploadButton').show();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -118,6 +128,7 @@ function uploadFile(uploadButton){
|
|||||||
showFinished();
|
showFinished();
|
||||||
hideProgress();
|
hideProgress();
|
||||||
hideError();
|
hideError();
|
||||||
|
$('#uploadButton').show();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,13 @@
|
|||||||
<div>Ich lade jetzt die Datei hoch... Pieps.</div>
|
<div>Ich lade jetzt die Datei hoch... Pieps.</div>
|
||||||
<div><img src="/agenda/planung/image/upload/bird9.gif" /></div>
|
<div><img src="/agenda/planung/image/upload/bird9.gif" /></div>
|
||||||
<div>Ist das aufregend!</div>
|
<div>Ist das aufregend!</div>
|
||||||
<progress id="progressBar"></progress>
|
<!--<progress id="progressBar"></progress>-->
|
||||||
|
|
||||||
|
<div id="progress_container">
|
||||||
|
<div id="progress_done"></div>
|
||||||
|
<div id="progress_todo"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="progressLabel"></div>
|
<div id="progressLabel"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user