Skip to content

Commit efa4a38

Browse files
André DietrichAndré Dietrich
authored andcommitted
fix: video and audio injection with #timestamps
1 parent 2606062 commit efa4a38

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

src/components/Preview.vue

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (window.LIA.settings?.preferBrowserTTS || false) {
1111
window.injectHandler = function (param) {
1212
let url
1313
14-
console.log("injecting", param)
14+
console.log("injecting ->", param)
1515
1616
if (blob[param.src]) {
1717
url = blob[param.src]
@@ -25,6 +25,11 @@ window.injectHandler = function (param) {
2525
2626
const src = window.location.origin + param.src
2727
28+
// Media fragment (e.g. "#t=0,5") that has to be re-applied to the blob URL so
29+
// the author's start/stop time keeps working. Blob URLs lose any fragment.
30+
const hashIndex = param.src.indexOf("#")
31+
const fragment = hashIndex >= 0 ? param.src.slice(hashIndex) : ""
32+
2833
switch (param.tag) {
2934
case "img": {
3035
const images = document.querySelectorAll('img,picture')
@@ -49,13 +54,13 @@ window.injectHandler = function (param) {
4954
5055
for (let i = 0; i < nodes.length; i++) {
5156
let elem = nodes[i]
52-
if (elem.src == src) {
57+
if (elem.src == src + fragment) {
5358
const parent = elem.parentNode
5459
if (!parent.paused) {
5560
parent.pause()
5661
}
5762
58-
elem.src = url
63+
elem.src = url + fragment
5964
elem.removeAttribute("onerror")
6065
6166
// this forces the player to reload
@@ -72,10 +77,10 @@ window.injectHandler = function (param) {
7277
7378
for (let i = 0; i < nodes.length; i++) {
7479
let elem = nodes[i]
75-
if (elem.src == src) {
80+
if (elem.src == src + fragment) {
7681
const parent = elem.parentNode
77-
parent.src = url
78-
elem.src = url
82+
parent.src = url + fragment
83+
elem.src = url + fragment
7984
parent.load()
8085
parent.onloadeddata = function() {
8186
parent.play()
@@ -89,7 +94,7 @@ window.injectHandler = function (param) {
8994
let elem = nodes[i]
9095
9196
if (elem.src == src) {
92-
elem.src = url
97+
elem.src = url + fragment
9398
elem.load()
9499
elem.onloadeddata = function() {
95100
elem.play()
@@ -171,8 +176,11 @@ export default {
171176
const param = event.data.param;
172177
173178
if (this.fetchError) {
174-
const blob = this.fetchError(param.src);
175-
//(param.tag, param.src);
179+
// Strip any media fragment (e.g. "#t=0,5") so the virtual file
180+
// system can find the file by its real path. The fragment stays
181+
// in param.src so injectHandler can re-apply it to the blob URL.
182+
const lookupSrc = param.src.split("#")[0];
183+
const blob = this.fetchError(lookupSrc);
176184
if (blob) {
177185
this.sendToLia("inject", {
178186
tag: param.tag,

0 commit comments

Comments
 (0)