mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-03-22 15:15:38 +00:00
HLS player updates
This commit is contained in:
@@ -2,9 +2,11 @@ import { TimeRangesStub } from "./TimeRangesStub.js"
|
||||
import { TextTrackStub, TextTrackListStub } from "./TextTrackStub.js"
|
||||
|
||||
export class VideoElementStub extends EventTarget {
|
||||
constructor() {
|
||||
constructor(id) {
|
||||
super();
|
||||
|
||||
this.instanceId = id;
|
||||
|
||||
this.bridgeId = window.nextInternalId;
|
||||
window.nextInternalId += 1;
|
||||
window.bridgeObjectMap[this.bridgeId] = this;
|
||||
@@ -23,13 +25,14 @@ export class VideoElementStub extends EventTarget {
|
||||
this.autoplay = false;
|
||||
this.controls = false;
|
||||
this.error = null;
|
||||
this.src = '';
|
||||
this._src = '';
|
||||
this.videoWidth = 0;
|
||||
this.videoHeight = 0;
|
||||
this.textTracks = new TextTrackListStub();
|
||||
this.isWaiting = false;
|
||||
|
||||
window.bridgeInvokeAsync(this.bridgeId, "VideoElement", "constructor", {
|
||||
"instanceId": this.instanceId
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
@@ -52,6 +55,7 @@ export class VideoElementStub extends EventTarget {
|
||||
this.dispatchEvent(new Event('seeking'));
|
||||
|
||||
window.bridgeInvokeAsync(this.bridgeId, "VideoElement", "setCurrentTime", {
|
||||
"instanceId": this.instanceId,
|
||||
"currentTime": value
|
||||
}).then((result) => {
|
||||
this.dispatchEvent(new Event('seeked'));
|
||||
@@ -59,6 +63,33 @@ export class VideoElementStub extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
get src() {
|
||||
return this._src;
|
||||
}
|
||||
|
||||
set src(value) {
|
||||
this._src = value;
|
||||
var media = window.mediaSourceMap[this._src];
|
||||
if (media) {
|
||||
window.bridgeInvokeAsync(this.bridgeId, "VideoElement", "setMediaSource", {
|
||||
"instanceId": this.instanceId,
|
||||
"mediaSourceId": media.bridgeId
|
||||
}).then((result) => {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
removeAttribute(name) {
|
||||
if (name === "src") {
|
||||
this._src = "";
|
||||
}
|
||||
}
|
||||
|
||||
querySelectorAll(name) {
|
||||
const fragment = document.createDocumentFragment();
|
||||
return fragment.querySelectorAll('*');
|
||||
}
|
||||
|
||||
bridgeUpdateBuffered(value) {
|
||||
const updatedRanges = value;
|
||||
var ranges = [];
|
||||
@@ -103,6 +134,7 @@ export class VideoElementStub extends EventTarget {
|
||||
play() {
|
||||
if (this.paused) {
|
||||
return window.bridgeInvokeAsync(this.bridgeId, "VideoElement", "play", {
|
||||
"instanceId": this.instanceId,
|
||||
}).then((result) => {
|
||||
this.dispatchEvent(new Event('play'));
|
||||
this.dispatchEvent(new Event('playing'));
|
||||
@@ -118,6 +150,7 @@ export class VideoElementStub extends EventTarget {
|
||||
this.dispatchEvent(new Event('pause'));
|
||||
|
||||
return window.bridgeInvokeAsync(this.bridgeId, "VideoElement", "pause", {
|
||||
"instanceId": this.instanceId,
|
||||
}).then((result) => {
|
||||
})
|
||||
}
|
||||
@@ -131,43 +164,12 @@ export class VideoElementStub extends EventTarget {
|
||||
return window.mediaSourceMap[this.src];
|
||||
}
|
||||
|
||||
/*_simulateTimeUpdate() {
|
||||
if (this._isPlaying) {
|
||||
// Simulate time progression
|
||||
setTimeout(() => {
|
||||
var bufferedEnd = 0.0;
|
||||
|
||||
const media = this._getMedia();
|
||||
if (media) {
|
||||
if (media.sourceBuffers.length != 0) {
|
||||
this.buffered = media.sourceBuffers._buffers[0].buffered;
|
||||
bufferedEnd = this.buffered.length == 0 ? 0 : this.buffered.end(this.buffered.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Consume buffered data
|
||||
if (this.currentTime < bufferedEnd) {
|
||||
// Advance currentTime
|
||||
this._currentTime += 0.1 * this.playbackRate; // Increment currentTime
|
||||
this.dispatchEvent(new Event('timeupdate'));
|
||||
|
||||
// Continue simulation
|
||||
this._simulateTimeUpdate();
|
||||
} else {
|
||||
console.log("Buffer underrun");
|
||||
// Buffer underrun
|
||||
this._isPlaying = false;
|
||||
this.paused = true;
|
||||
this.dispatchEvent(new Event('waiting'));
|
||||
// The player should react by buffering more data
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}*/
|
||||
|
||||
addTextTrack(kind, label, language) {
|
||||
const textTrack = new TextTrackStub(kind, label, language);
|
||||
this.textTracks._add(textTrack);
|
||||
return textTrack;
|
||||
}
|
||||
|
||||
load() {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user