aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/static
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2021-08-26 20:48:50 -0700
committerJesús <heckyel@hyperbola.info>2021-08-29 21:53:21 -0500
commit1c591b445738a3bb217d59424adcb4e9ea5b596e (patch)
tree42623413ab68cbab47c9de72554d92b893f7b166 /youtube/static
parent6e39ae19b6b38a24ae7b6e7d8c1321eaad40d397 (diff)
downloadyt-local-1c591b445738a3bb217d59424adcb4e9ea5b596e.tar.lz
yt-local-1c591b445738a3bb217d59424adcb4e9ea5b596e.tar.xz
yt-local-1c591b445738a3bb217d59424adcb4e9ea5b596e.zip
av-merge: call mediaSource.endOfStream() so player pauses at end
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'youtube/static')
-rw-r--r--youtube/static/js/av-merge.js39
1 files changed, 35 insertions, 4 deletions
diff --git a/youtube/static/js/av-merge.js b/youtube/static/js/av-merge.js
index 13551fb..cf1210a 100644
--- a/youtube/static/js/av-merge.js
+++ b/youtube/static/js/av-merge.js
@@ -17,8 +17,6 @@
// SourceBuffer data limits:
// https://developers.google.com/web/updates/2017/10/quotaexceedederror
-// TODO: close stream at end?
-// TODO: Better buffering algorithm
// TODO: Call abort to cancel in-progress appends?
@@ -38,6 +36,9 @@ function AVMerge(video, srcPair, startTime){
this.video = video;
this.mediaSource = null;
this.closed = false;
+ this.opened = false;
+ this.audioEndOfStreamCalled = false;
+ this.videoEndOfStreamCalled = false;
this.setup();
}
AVMerge.prototype.setup = function() {
@@ -55,6 +56,14 @@ AVMerge.prototype.setup = function() {
}
AVMerge.prototype.sourceOpen = function(_) {
+ // If after calling mediaSource.endOfStream, the user seeks back
+ // into the video, the sourceOpen event will be fired again. Do not
+ // overwrite the streams.
+ this.audioEndOfStreamCalled = false;
+ this.videoEndOfStreamCalled = false;
+ if (this.opened)
+ return;
+ this.opened = true;
this.videoStream = new Stream(this, this.videoSource, this.startTime);
this.audioStream = new Stream(this, this.audioSource, this.startTime);
@@ -88,9 +97,23 @@ AVMerge.prototype.seek = function(e) {
this.videoStream.handleSeek();
this.seeking = false;
} else {
- this.reportWarning('seek but not open? readyState:',
- this.mediaSource.readyState);
+ reportWarning('seek but not open? readyState:',
+ this.mediaSource.readyState);
+ }
+}
+AVMerge.prototype.audioEndOfStream = function() {
+ if (this.videoEndOfStreamCalled && !this.audioEndOfStreamCalled) {
+ reportDebug('Calling mediaSource.endOfStream()');
+ this.mediaSource.endOfStream();
+ }
+ this.audioEndOfStreamCalled = true;
+}
+AVMerge.prototype.videoEndOfStream = function() {
+ if (this.audioEndOfStreamCalled && !this.videoEndOfStreamCalled) {
+ reportDebug('Calling mediaSource.endOfStream()');
+ this.mediaSource.endOfStream();
}
+ this.videoEndOfStreamCalled = true;
}
function Stream(avMerge, source, startTime) {
@@ -259,6 +282,14 @@ Stream.prototype.checkBuffer = async function() {
if (i < this.sidx.entries.length && !this.sidx.entries[i].requested) {
this.fetchSegment(i);
+ // We are playing the last segment and we have it.
+ // Signal the end of stream
+ } else if (currentSegmentIdx == this.sidx.entries.length - 1
+ && this.sidx.entries[currentSegmentIdx].have) {
+ if (this.streamType == 'audio')
+ this.avMerge.audioEndOfStream();
+ else
+ this.avMerge.videoEndOfStream();
}
}
Stream.prototype.segmentInBuffer = function(segmentIdx) {