@@ -164,9 +164,8 @@ export class VideoRTC extends HTMLElement {
164164 * https://developer.chrome.com/blog/autoplay/
165165 */
166166 play ( ) {
167- this . video . play ( ) . catch ( er => {
168- const isAutoplayError = er . name === 'NotAllowedError' ;
169- if ( ! this . video . muted && isAutoplayError ) {
167+ this . video . play ( ) . catch ( ( ) => {
168+ if ( ! this . video . muted ) {
170169 this . video . muted = true ;
171170 this . video . play ( ) . catch ( er => {
172171 console . warn ( er ) ;
@@ -440,24 +439,30 @@ export class VideoRTC extends HTMLElement {
440439 const sb = ms . addSourceBuffer ( msg . value ) ;
441440 sb . mode = 'segments' ; // segments or sequence
442441 sb . addEventListener ( 'updateend' , ( ) => {
443- if ( sb . updating ) return ;
444-
445- try {
446- if ( bufLen > 0 ) {
442+ if ( ! sb . updating && bufLen > 0 ) {
443+ try {
447444 const data = buf . slice ( 0 , bufLen ) ;
448- bufLen = 0 ;
449445 sb . appendBuffer ( data ) ;
450- } else if ( sb . buffered && sb . buffered . length ) {
451- const end = sb . buffered . end ( sb . buffered . length - 1 ) - 15 ;
452- const start = sb . buffered . start ( 0 ) ;
453- if ( end > start ) {
454- sb . remove ( start , end ) ;
455- ms . setLiveSeekableRange ( end , end + 15 ) ;
456- }
457- // console.debug("VideoRTC.buffered", start, end);
446+ bufLen = 0 ;
447+ } catch ( e ) {
448+ // console.debug(e);
449+ }
450+ }
451+
452+ if ( ! sb . updating && sb . buffered && sb . buffered . length ) {
453+ const end = sb . buffered . end ( sb . buffered . length - 1 ) ;
454+ const start = end - 5 ;
455+ const start0 = sb . buffered . start ( 0 ) ;
456+ if ( start > start0 ) {
457+ sb . remove ( start0 , start ) ;
458+ ms . setLiveSeekableRange ( start , end ) ;
459+ }
460+ if ( this . video . currentTime < start ) {
461+ this . video . currentTime = start ;
458462 }
459- } catch ( e ) {
460- // console.debug(e);
463+ const gap = end - this . video . currentTime ;
464+ this . video . playbackRate = gap > 0.1 ? gap : 0.1 ;
465+ // console.debug('VideoRTC.buffered', gap, this.video.playbackRate, this.video.readyState);
461466 }
462467 } ) ;
463468
@@ -469,7 +474,7 @@ export class VideoRTC extends HTMLElement {
469474 const b = new Uint8Array ( data ) ;
470475 buf . set ( b , bufLen ) ;
471476 bufLen += b . byteLength ;
472- // console.debug(" VideoRTC.buffer" , b.byteLength, bufLen);
477+ // console.debug(' VideoRTC.buffer' , b.byteLength, bufLen);
473478 } else {
474479 try {
475480 sb . appendBuffer ( data ) ;
0 commit comments