fix audio offset with negative numbers
This commit is contained in:
parent
9a8509e56d
commit
1e9bc1f471
1 changed files with 14 additions and 8 deletions
|
@ -380,7 +380,7 @@ class Annotator {
|
||||||
start: [this.currentTime, this.duration],
|
start: [this.currentTime, this.duration],
|
||||||
connect: true,
|
connect: true,
|
||||||
range: {
|
range: {
|
||||||
'min': 0,
|
'min': this.audioOffset < 0 ? this.audioOffset * 1000 : 0,
|
||||||
'max': this.duration
|
'max': this.duration
|
||||||
},
|
},
|
||||||
tooltips: [
|
tooltips: [
|
||||||
|
@ -422,7 +422,8 @@ class Annotator {
|
||||||
if (metadata) {
|
if (metadata) {
|
||||||
this.annotations = metadata.annotations;
|
this.annotations = metadata.annotations;
|
||||||
this.audioFile = metadata.hasOwnProperty('audio') ? metadata.audio.file : null;
|
this.audioFile = metadata.hasOwnProperty('audio') ? metadata.audio.file : null;
|
||||||
this.audioOffset = metadata.hasOwnProperty('audio') ? metadata.audio.offset : 0;
|
this.audioOffset = metadata.hasOwnProperty('audio') ? Number.parseFloat(metadata.audio.offset) : 0;
|
||||||
|
this.currentTime = this.audioOffset < 0 ? this.audioOffset * 1000 : 0;
|
||||||
//
|
//
|
||||||
// load any saved metadata
|
// load any saved metadata
|
||||||
}
|
}
|
||||||
|
@ -449,11 +450,16 @@ class Annotator {
|
||||||
this.formatter = wNumb({
|
this.formatter = wNumb({
|
||||||
decimals: 2,
|
decimals: 2,
|
||||||
edit: (time) => {
|
edit: (time) => {
|
||||||
|
let neg = "";
|
||||||
|
if(time < 0) {
|
||||||
|
neg = "-";
|
||||||
|
time *= -1;
|
||||||
|
}
|
||||||
const s = Math.floor(time / 1000);
|
const s = Math.floor(time / 1000);
|
||||||
const minutes = Math.floor(s / 60);
|
const minutes = Math.floor(s / 60);
|
||||||
const seconds = s - minutes * 60;
|
const seconds = s - minutes * 60;
|
||||||
const ms = Math.floor((time / 1000 - s) * 1000);
|
const ms = Math.floor((time / 1000 - s) * 1000);
|
||||||
return `${minutes}:${seconds}:${ms}`;
|
return `${neg}${minutes}:${seconds}:${ms}`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -531,9 +537,10 @@ class Annotator {
|
||||||
}
|
}
|
||||||
|
|
||||||
setAudioOffset(audioOffset) {
|
setAudioOffset(audioOffset) {
|
||||||
this.audioOffset = audioOffset;
|
this.audioOffset = Number.parseFloat(audioOffset);
|
||||||
// TODO update playhead
|
// TODO update playhead
|
||||||
// TODO update this.duration
|
// TODO update this.duration
|
||||||
|
this.setUpAnnotator(); // if offset is negative, annotator starts at negative time
|
||||||
this.updateState();
|
this.updateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +549,7 @@ class Annotator {
|
||||||
* @returns float
|
* @returns float
|
||||||
*/
|
*/
|
||||||
getAudioTime(time) {
|
getAudioTime(time) {
|
||||||
return Number.parseFloat(time) + (this.audioOffset * 1000 ?? 0);
|
return Number.parseFloat(time) - (this.audioOffset * 1000 ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -558,14 +565,13 @@ class Annotator {
|
||||||
const t_start = this.getAudioTime(t_in); // in ms
|
const t_start = this.getAudioTime(t_in); // in ms
|
||||||
const t_diff = t_out - t_in; // in ms
|
const t_diff = t_out - t_in; // in ms
|
||||||
|
|
||||||
console.log('set time', t_in, t_start, typeof t_start, typeof t_in, t_start < 0);
|
|
||||||
this.audioEl.pause();
|
this.audioEl.pause();
|
||||||
|
|
||||||
if (t_start < 0) {
|
if (t_start < 0) {
|
||||||
if (t_diff <= t_start * -1) {
|
if (t_diff <= t_start * -1) {
|
||||||
console.log('no audio playback in segment', t_start, t_diff);
|
console.debug('no audio playback in segment', t_start, t_diff);
|
||||||
} else {
|
} else {
|
||||||
console.log('huh?', t_start, t_diff);
|
console.debug('delay audio playback', t_start, t_diff);
|
||||||
// a negative audiooffset delays playback from the start
|
// a negative audiooffset delays playback from the start
|
||||||
// this.audioStartTimeout = setTimeout((e) => this.audioEl.play(), t*-1000);
|
// this.audioStartTimeout = setTimeout((e) => this.audioEl.play(), t*-1000);
|
||||||
this.audioStartTimeout = setTimeout((e) => { this.audioEl.currentTime = 0 }, t_start * -1); // triggers play with "seeked" event
|
this.audioStartTimeout = setTimeout((e) => { this.audioEl.currentTime = 0 }, t_start * -1); // triggers play with "seeked" event
|
||||||
|
|
Loading…
Reference in a new issue