Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1 goes into a loop on detaching and re-attaching media #3732

Closed
3 of 5 tasks
rchl opened this issue Apr 6, 2021 · 11 comments · Fixed by #3754
Closed
3 of 5 tasks

v1 goes into a loop on detaching and re-attaching media #3732

rchl opened this issue Apr 6, 2021 · 11 comments · Fixed by #3754
Labels
Bug Regression A bug introduced in a recent release
Milestone

Comments

@rchl
Copy link

rchl commented Apr 6, 2021

What version of Hls.js are you using?

v1.0.0

What browser and OS (including versions) are you using?

Chrome 89 on macOS 11.2.3

Test stream:

https://codesandbox.io/s/hls-v1-bug-1n63v?file=/index.html

Configuration:

defaults

Checklist

  • The stream has correct Access-Control-Allow-Origin headers (CORS)
  • There are no network errors such as 404s in the browser console when trying to play the stream

Steps to reproduce

  1. Set up an instance with hls.loadSource() called from the MEDIA_ATTACHED event and video.play() called from the MANIFEST_PARSED event.
  2. Once the stream loads initially, call:
hls.stopLoad();
hls.detachMedia();
  1. Then call:
hls.attachMedia(video);

Expected behavior

The stream starts playing again.

Actual behavior

The video goes into some loop, playing and pausing constantly. The event logs shows that the MEDIA_ATTACHED event is called twice after step 3.

Console output

22:43:35.115 hls.js@latest:1 [log] > [stream-controller]: IDLE->STOPPED
22:43:35.115 hls.js@latest:1 [log] > [subtitle-stream-controller]: IDLE->STOPPED
22:43:35.115 hls.js@latest:1 [log] > detachMedia
22:43:35.116 hls.js@latest:1 [log] > [buffer-controller]: media source detaching
22:43:39.936 hls.js@latest:1 [log] > attachMedia
22:43:39.938 hls.js@latest:1 [log] > [buffer-controller]: Media source opened
22:43:39.939 hls.js@latest:1 [log] > [buffer-controller]: Updating Media Source duration to 634.575
22:43:39.939 hls.js@latest:1 [log] > [stream-controller]: STOPPED->IDLE
22:43:39.939 hls.js@latest:1 [log] > [stream-controller]: Loading fragment 0 cc: 0 of [0-63] level: 4, target: 0.008
22:43:39.940 hls.js@latest:1 [log] > [stream-controller]: IDLE->FRAG_LOADING
22:43:39.943 hls.js@latest:1 [log] > [subtitle-stream-controller]: STOPPED->IDLE
22:43:39.943 (index):23 MEDIA_ATTACHED
22:43:39.943 hls.js@latest:1 [log] > stopLoad
22:43:39.944 hls.js@latest:1 [log] > [stream-controller]: FRAG_LOADING->STOPPED
22:43:39.944 hls.js@latest:1 [log] > [subtitle-stream-controller]: IDLE->STOPPED
22:43:39.944 hls.js@latest:1 [log] > detachMedia
22:43:39.944 hls.js@latest:1 [log] > [buffer-controller]: media source detaching
22:43:39.946 hls.js@latest:1 [log] > attachMedia
22:43:39.946 hls.js@latest:1 [log] > loadSource:https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8
22:43:39.947 hls.js@latest:1 [log] > [stream-controller]: Trigger BUFFER_RESET
22:43:39.950 hls.js@latest:1 [log] > [buffer-controller]: Media source opened
22:43:39.950 hls.js@latest:1 [log] > [buffer-controller]: Updating Media Source duration to 634.575
22:43:39.950 hls.js@latest:1 [log] > [stream-controller]: STOPPED->IDLE
22:43:39.950 hls.js@latest:1 [log] > [stream-controller]: Loading fragment 0 cc: 0 of [0-63] level: 4, target: 0.008
22:43:39.951 hls.js@latest:1 [log] > [stream-controller]: IDLE->FRAG_LOADING
22:43:39.953 hls.js@latest:1 [log] > [subtitle-stream-controller]: STOPPED->IDLE
22:43:39.954 (index):23 MEDIA_ATTACHED
22:43:39.954 hls.js@latest:1 [log] > stopLoad
22:43:39.954 hls.js@latest:1 [log] > [stream-controller]: FRAG_LOADING->STOPPED
22:43:39.954 hls.js@latest:1 [log] > [subtitle-stream-controller]: IDLE->STOPPED
22:43:39.954 hls.js@latest:1 [log] > detachMedia
22:43:39.954 hls.js@latest:1 [log] > [buffer-controller]: media source detaching
22:43:39.955 hls.js@latest:1 [log] > attachMedia
22:43:39.956 hls.js@latest:1 [log] > loadSource:https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8
22:43:39.956 hls.js@latest:1 [log] > [stream-controller]: Trigger BUFFER_RESET
22:43:39.961 hls.js@latest:1 [log] > [level-controller]: manifest loaded, 5 level(s) found, first bitrate: 2149280
22:43:39.962 hls.js@latest:1 [log] > 1 bufferCodec event(s) expected
22:43:39.962 (index):27 MANIFEST_PARSED
22:43:39.962 hls.js@latest:1 [log] > startLoad(-1)
22:43:39.963 hls.js@latest:1 [log] > [level-controller]: Attempt loading level index 4 with URL-id 0 https://test-streams.mux.dev/x36xhzz/url_8/193039199_mp4_h264_aac_fhd_7.m3u8
22:43:39.964 hls.js@latest:1 [log] > [level-controller]: switching to level 3 from 4
22:43:39.964 hls.js@latest:1 [log] > [level-controller]: Attempt loading level index 3 with URL-id 0 https://test-streams.mux.dev/x36xhzz/url_0/193039199_mp4_h264_aac_hd_7.m3u8
22:43:39.965 hls.js@latest:1 [log] > [playlist-loader]: aborting previous loader for type: level
22:43:39.966 hls.js@latest:1 [log] > [stream-controller]: STOPPED->IDLE
22:43:39.967 hls.js@latest:1 [log] > [subtitle-stream-controller]: STOPPED->IDLE
22:43:39.970 hls.js@latest:1 [log] > [buffer-controller]: Media source opened
22:43:39.970 (index):23 MEDIA_ATTACHED
22:43:39.970 hls.js@latest:1 [log] > stopLoad
22:43:39.970 hls.js@latest:1 [log] > [stream-controller]: IDLE->STOPPED
22:43:39.970 hls.js@latest:1 [log] > [subtitle-stream-controller]: IDLE->STOPPED
22:43:39.971 hls.js@latest:1 [log] > detachMedia
22:43:39.971 hls.js@latest:1 [log] > [buffer-controller]: media source detaching
22:43:39.972 hls.js@latest:1 [log] > attachMedia
22:43:39.973 hls.js@latest:1 [log] > loadSource:https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8
22:43:39.973 hls.js@latest:1 [log] > [stream-controller]: Trigger BUFFER_RESET
22:43:39.977 hls.js@latest:1 [log] > [stream-controller]: Level 3 loaded [0,63], cc [0, 0] duration:634.584
22:43:39.978 hls.js@latest:1 Uncaught (in promise) DOMException: The play() request was interrupted by a new load request. https://goo.gl/LdLk22
22:43:39.978 hls.js@latest:1 [log] > [buffer-controller]: Media source opened
22:43:39.978 hls.js@latest:1 [log] > [buffer-controller]: Updating Media Source duration to 634.584
22:43:39.979 hls.js@latest:1 [log] > [stream-controller]: STOPPED->IDLE
22:43:39.979 hls.js@latest:1 [log] > [stream-controller]: Loading fragment 0 cc: 0 of [0-63] level: 3, target: 0
22:43:39.979 hls.js@latest:1 [log] > [stream-controller]: IDLE->FRAG_LOADING
22:43:39.981 hls.js@latest:1 [log] > [subtitle-stream-controller]: STOPPED->IDLE
22:43:39.982 (index):23 MEDIA_ATTACHED
[and so on...]
@rchl
Copy link
Author

rchl commented Apr 6, 2021

This works fine with version <1.0

rchl added a commit to resoai/TileBoard that referenced this issue Apr 7, 2021
Appears to be a regression in v1 of hls.js. An upstream issue created
at video-dev/hls.js#3732

But I also found similar issue (video-dev/hls.js#2473)
that seems to suggest that it's best to just re-initialize the Hls
instance instead of re-attaching the media so I'll just go with that
for now.

Fixes #688
alphasixtyfive pushed a commit to resoai/TileBoard that referenced this issue Apr 7, 2021
* fix(CAMERA_STREAM): stream fails to resume after being suspended

Appears to be a regression in v1 of hls.js. An upstream issue created
at video-dev/hls.js#3732

But I also found similar issue (video-dev/hls.js#2473)
that seems to suggest that it's best to just re-initialize the Hls
instance instead of re-attaching the media so I'll just go with that
for now.

Fixes #688

* revert debugging code

* debug code
@robwalch
Copy link
Collaborator

robwalch commented Apr 9, 2021

I recommend calling hls.loadSource(url); before hls.attachMedia(video); as our demo page does.

Once the stream loads initially, call:

If MANIFEST_PARSED has fired some of the stream has loaded. Do you mean after video has buffered? Has playback started at this point?

Then call: hls.attachMedia(video);

Synchonously after hls.detachMedia(); or after a delay / DETACHED events?

@robwalch
Copy link
Collaborator

robwalch commented Apr 9, 2021

Set up an instance with hls.loadSource() called from the MEDIA_ATTACHED

OK I see what's happening here.

@robwalch robwalch added Bug and removed Need info labels Apr 9, 2021
@robwalch robwalch added this to the 1.0.1 milestone Apr 9, 2021
@robwalch robwalch added this to Top priorities in Release Planning and Backlog via automation Apr 9, 2021
robwalch pushed a commit that referenced this issue Apr 9, 2021
… recursive calls when handlers call loadSource)

Resolves #3732
@robwalch
Copy link
Collaborator

robwalch commented Apr 9, 2021

Hi @rchl,

Thanks for the bug report. #3754 should fix this issue. Can you confirm by trying this build with your test case? Thanks!

https://deploy-preview-3754--hls-js-dev.netlify.app/dist/hls.js

@rchl
Copy link
Author

rchl commented Apr 10, 2021

The fix works for the issue with getting into the loading loop.

A sandbox using the fixed version is at https://codesandbox.io/s/hls-v1-bug-try-fix-9wr6b?file=/index.html

But I wonder if it's correct that re-attaching triggers double MANIFEST_PARSED and MEDIA_ATTACHED events. I imagine that could still cause issues, depending on what one does within those listeners.

Below is a log on re-attaching the media. You can see that MEDIA_ATTACHED is called 3 times while MANIFEST_PARSED is called twice.

Log
[log] > attachMedia
10:36:19.514 buffer-controller.ts:736 [log] > [buffer-controller]: Media source opened
10:36:19.515 buffer-controller.ts:628 [log] > [buffer-controller]: Updating Media Source duration to 634.575
10:36:19.515 base-stream-controller.ts:1277 [log] > [stream-controller]: STOPPED->IDLE
10:36:19.515 base-stream-controller.ts:552 [log] > [stream-controller]: Loading fragment 0 cc: 0 of [0-63] level: 4, target: 0.008
10:36:19.515 base-stream-controller.ts:1277 [log] > [stream-controller]: IDLE->FRAG_LOADING
10:36:19.517 base-stream-controller.ts:1277 [log] > [subtitle-stream-controller]: STOPPED->IDLE
10:36:19.517 (index):23 MEDIA_ATTACHED
10:36:19.517 hls.ts:354 [log] > stopLoad
10:36:19.517 base-stream-controller.ts:1277 [log] > [stream-controller]: FRAG_LOADING->STOPPED
10:36:19.518 base-stream-controller.ts:1277 [log] > [subtitle-stream-controller]: IDLE->STOPPED
10:36:19.518 hls.ts:311 [log] > detachMedia
10:36:19.518 buffer-controller.ts:155 [log] > [buffer-controller]: media source detaching
10:36:19.519 hls.ts:302 [log] > attachMedia
10:36:19.519 hls.ts:330 [log] > loadSource:https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8
10:36:19.520 stream-controller.ts:539 [log] > [stream-controller]: Trigger BUFFER_RESET
10:36:19.526 buffer-controller.ts:736 [log] > [buffer-controller]: Media source opened
10:36:19.526 buffer-controller.ts:628 [log] > [buffer-controller]: Updating Media Source duration to 634.575
10:36:19.527 base-stream-controller.ts:1277 [log] > [stream-controller]: STOPPED->IDLE
10:36:19.527 base-stream-controller.ts:552 [log] > [stream-controller]: Loading fragment 0 cc: 0 of [0-63] level: 4, target: 0.008
10:36:19.527 base-stream-controller.ts:1277 [log] > [stream-controller]: IDLE->FRAG_LOADING
10:36:19.529 base-stream-controller.ts:1277 [log] > [subtitle-stream-controller]: STOPPED->IDLE
10:36:19.529 (index):23 MEDIA_ATTACHED
10:36:19.529 hls.ts:354 [log] > stopLoad
10:36:19.530 base-stream-controller.ts:1277 [log] > [stream-controller]: FRAG_LOADING->STOPPED
10:36:19.530 base-stream-controller.ts:1277 [log] > [subtitle-stream-controller]: IDLE->STOPPED
10:36:19.530 hls.ts:311 [log] > detachMedia
10:36:19.530 buffer-controller.ts:155 [log] > [buffer-controller]: media source detaching
10:36:19.531 hls.ts:302 [log] > attachMedia
10:36:19.531 hls.ts:330 [log] > loadSource:https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8
10:36:19.532 stream-controller.ts:539 [log] > [stream-controller]: Trigger BUFFER_RESET
10:36:19.534 level-controller.ts:171 [log] > [level-controller]: manifest loaded, 5 level(s) found, first bitrate: 2149280
10:36:19.534 buffer-controller.ts:129 [log] > 1 bufferCodec event(s) expected
10:36:19.534 (index):27 MANIFEST_PARSED
10:36:19.534 hls.ts:344 [log] > startLoad(-1)
10:36:19.534 level-controller.ts:523 [log] > [level-controller]: Attempt loading level index 4 with URL-id 0 https://test-streams.mux.dev/x36xhzz/url_8/193039199_mp4_h264_aac_fhd_7.m3u8
10:36:19.535 level-controller.ts:250 [log] > [level-controller]: switching to level 3 from 4
10:36:19.536 level-controller.ts:523 [log] > [level-controller]: Attempt loading level index 3 with URL-id 0 https://test-streams.mux.dev/x36xhzz/url_0/193039199_mp4_h264_aac_hd_7.m3u8
10:36:19.536 playlist-loader.ts:219 [log] > [playlist-loader]: aborting previous loader for type: level
10:36:19.541 base-stream-controller.ts:1277 [log] > [stream-controller]: STOPPED->IDLE
10:36:19.542 base-stream-controller.ts:1277 [log] > [subtitle-stream-controller]: STOPPED->IDLE
10:36:19.550 stream-controller.ts:603 [log] > [stream-controller]: Level 3 loaded [0,63], cc [0, 0] duration:634.584
10:36:19.551 buffer-controller.ts:628 [log] > [buffer-controller]: Updating Media Source duration to 634.584
10:36:19.551 buffer-controller.ts:736 [log] > [buffer-controller]: Media source opened
10:36:19.551 (index):23 MEDIA_ATTACHED
10:36:19.552 hls.ts:354 [log] > stopLoad
10:36:19.552 base-stream-controller.ts:1277 [log] > [stream-controller]: IDLE->STOPPED
10:36:19.552 base-stream-controller.ts:1277 [log] > [subtitle-stream-controller]: IDLE->STOPPED
10:36:19.553 hls.ts:330 [log] > loadSource:https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8
10:36:19.553 stream-controller.ts:539 [log] > [stream-controller]: Trigger BUFFER_RESET
10:36:19.561 level-controller.ts:171 [log] > [level-controller]: manifest loaded, 5 level(s) found, first bitrate: 2149280
10:36:19.561 buffer-controller.ts:129 [log] > 1 bufferCodec event(s) expected
10:36:19.561 (index):27 MANIFEST_PARSED
10:36:19.561 hls.ts:344 [log] > startLoad(-1)
10:36:19.561 level-controller.ts:523 [log] > [level-controller]: Attempt loading level index 3 with URL-id 0 https://test-streams.mux.dev/x36xhzz/url_0/193039199_mp4_h264_aac_hd_7.m3u8
10:36:19.562 level-controller.ts:250 [log] > [level-controller]: switching to level 3 from 3
10:36:19.563 level-controller.ts:523 [log] > [level-controller]: Attempt loading level index 3 with URL-id 0 https://test-streams.mux.dev/x36xhzz/url_0/193039199_mp4_h264_aac_hd_7.m3u8
10:36:19.563 base-stream-controller.ts:1277 [log] > [stream-controller]: STOPPED->IDLE
10:36:19.563 level-controller.ts:250 [log] > [level-controller]: switching to level 3 from 3
10:36:19.563 level-controller.ts:523 [log] > [level-controller]: Attempt loading level index 3 with URL-id 0 https://test-streams.mux.dev/x36xhzz/url_0/193039199_mp4_h264_aac_hd_7.m3u8
10:36:19.564 base-stream-controller.ts:1277 [log] > [stream-controller]: IDLE->WAITING_LEVEL
10:36:19.564 base-stream-controller.ts:1277 [log] > [subtitle-stream-controller]: STOPPED->IDLE
10:36:19.569 stream-controller.ts:603 [log] > [stream-controller]: Level 3 loaded [0,63], cc [0, 0] duration:634.584
10:36:19.569 base-stream-controller.ts:1277 [log] > [stream-controller]: WAITING_LEVEL->IDLE
10:36:19.569 base-stream-controller.ts:552 [log] > [stream-controller]: Loading fragment 0 cc: 0 of [0-63] level: 3, target: 0
10:36:19.570 base-stream-controller.ts:1277 [log] > [stream-controller]: IDLE->FRAG_LOADING
10:36:19.583 transmuxer-interface.ts:66 [log] > demuxing in webworker
10:36:19.587 transmuxer-interface.ts:180 [log] > [transmuxer-interface, main]: Starting new transmux session for sn: 0 p: -1 level: 3 id: 1
        discontinuity: true
        trackSwitch: true
        contiguous: false
        accurateTimeOffset: true
        timeOffset: 0
10:36:19.587 base-stream-controller.ts:326 [log] > [stream-controller]: Loaded fragment 0 of level 3
10:36:19.730 blob:https://9wr6b.c…ed-5e74346d04c0:603 [log] >
10:36:19.731 blob:https://9wr6b.c…d-5e74346d04c0:2692 [log] > [mp4-remuxer]: ISGenerated flag reset
10:36:19.732 blob:https://9wr6b.c…d-5e74346d04c0:2681 [log] > [mp4-remuxer]: initPTS & initDTS reset
10:36:19.737 blob:https://9wr6b.c…d-5e74346d04c0:7552 [log] > manifest codec:mp4a.40.2, ADTS type:2, samplingIndex:4
10:36:19.737 blob:https://9wr6b.c…d-5e74346d04c0:7714 [log] > parsed codec:mp4a.40.5, rate:44100, channels:2
10:36:19.763 blob:https://9wr6b.c…ed-5e74346d04c0:935 [log] > [transmuxer.ts]: Flushed fragment 0 of level 3
10:36:19.763 base-stream-controller.ts:1277 [log] > [stream-controller]: FRAG_LOADING->PARSING
10:36:19.764 stream-controller.ts:1199 [log] > [stream-controller]: Init audio buffer, container:audio/mp4, codecs[selected/level/parsed]=[mp4a.40.2/mp4a.40.2/mp4a.40.5]
10:36:19.764 stream-controller.ts:1210 [log] > [stream-controller]: Init video buffer, container:video/mp4, codecs[level/parsed]=[avc1.64001f/avc1.64001f]
10:36:19.764 buffer-controller.ts:697 [log] > [buffer-controller]: creating sourceBuffer(audio/mp4;codecs=mp4a.40.2)
10:36:19.764 buffer-controller.ts:697 [log] > [buffer-controller]: creating sourceBuffer(video/mp4;codecs=avc1.64001f)
10:36:19.766 base-stream-controller.ts:1277 [log] > [stream-controller]: PARSING->PARSED
10:36:19.779 base-stream-controller.ts:463 [log] > [stream-controller]: Buffered main sn: 0 of level 3 [0.023,10.008]
10:36:19.779 base-stream-controller.ts:1277 [log] > [stream-controller]: PARSED->IDLE
10:36:19.779 level-controller.ts:250 [log] > [level-controller]: switching to level 4 from 3
10:36:19.779 level-controller.ts:523 [log] > [level-controller]: Attempt loading level index 4 with URL-id 0 https://test-streams.mux.dev/x36xhzz/url_8/193039199_mp4_h264_aac_fhd_7.m3u8
10:36:19.780 base-stream-controller.ts:1277 [log] > [stream-controller]: IDLE->WAITING_LEVEL
10:36:19.787 stream-controller.ts:603 [log] > [stream-controller]: Level 4 loaded [0,63], cc [0, 0] duration:634.567
10:36:19.787 base-stream-controller.ts:1277 [log] > [stream-controller]: WAITING_LEVEL->IDLE
10:36:19.787 base-stream-controller.ts:552 [log] > [stream-controller]: Loading fragment 1 cc: 0 of [0-63] level: 4, target: 10.008
10:36:19.787 base-stream-controller.ts:1277 [log] > [stream-controller]: IDLE->FRAG_LOADING
10:36:19.802 gap-controller.ts:241 [warn] > skipping hole, adjusting currentTime from 0 to 0.1
_trySkipBufferHole @ gap-controller.ts:241
poll @ gap-controller.ts:130
checkBuffer @ stream-controller.ts:919
onTickEnd @ stream-controller.ts:196
doTick @ stream-controller.ts:191
tick @ task-loop.ts:110
onMediaPlaying @ stream-controller.ts:523
10:36:19.803 base-stream-controller.ts:194 [log] > [stream-controller]: media seeking to 0.100, state: FRAG_LOADING
10:36:19.804 base-stream-controller.ts:194 [log] > [audio-stream-controller]: media seeking to 0.100, state: STOPPED
10:36:19.861 transmuxer-interface.ts:180 [log] > [transmuxer-interface, main]: Starting new transmux session for sn: 1 p: -1 level: 4 id: 1
        discontinuity: false
        trackSwitch: true
        contiguous: false
        accurateTimeOffset: true
        timeOffset: 10
...

@robwalch
Copy link
Collaborator

robwalch commented Apr 10, 2021

You can see that MEDIA_ATTACHED is called 3 times while MANIFEST_PARSED is called twice.

We can avoid attaching a third time, but there is a reason for that. When you reattach after having already loaded a stream, you don't need to call loadSource again. Detaching destroys the MediaSource, but hls.js rememebers the url it loaded, so that when reattaching it can load it again (set config.autoStartLoad to false to prevent this). Because of this calling loadSource() on ATTACHED is redundant if you do it more than once for an instance of hls.js. You only need to call loadSource() again when you want to the instance to load a different URL (and v1.0.0 will detach and reattach for you).

Your example reloads on attaching and then must restart on attached becuase loadSource() was called again unnecessarily.

It's best to create a new instance when loading different streams, for a single stream, just do not call loadSource() again. I'm looking at changing the PR based on this, we should be able to deal with the redundant loadSource() calls, but if your event handler changes the url (adding a stream token for example) then the setup you have could still be problematic.

@rchl
Copy link
Author

rchl commented Apr 10, 2021

Thanks for the explanation.

I did decide to just change my code to destroy the instance instead of detaching (see resoai/TileBoard#692).

@MasterEvilAce
Copy link

MasterEvilAce commented Apr 10, 2021

So TLDR, you're doing it wrong if you want to load multiple streams without destroying the player. You need to detach, destroy, and then create a new instance and attach so that the attached handler calls loadSource without needing to detach the previous source. I'm looking at changing the PR based on this, (it gave me an idea)... 🟡 🦆

If you're loading one source, then changing to a new one, are you SUPPOSED to detach/reattach as common flow? I don't understand why you're supposed to detach if you're re-using 1 hls.js instance, and 1 video element. Can you not just wait for the video to end playing (OR call stopload) and then call loadSource with a new URL? This method seems to work fine for me in 1.0.0 EXCEPT for the fact that loadSource is calling MEDIA_ATTACHED, which makes no sense to me because the MEDIA isn't being detached (or manually reattached) from the video element.

For more details on my specific usage.. I am listening to MEDIA_ATTACHED to generate all the URLs that will be played in order, and it calls loadSource on the first one. On video event 'ended' I call loadSource again for the next URL, but it is triggering MEDIA_ATTACHED (so I have an IF statement to prevent my code running more than once.) I would assume MEDIA_ATTACHED should only logically be triggered when hls.attachMedia(video); is called.. but I am not detaching/reattaching. I only attach once after initializing hls.js.

@robwalch
Copy link
Collaborator

robwalch commented Apr 10, 2021

If codecs change then new SourceBuffers are required. That's why you would need to detach reattach. I'm looking at not automatically performing the detach/attach if the buffer controller has not been used yet.

I edited my last comment now as I work through the problem. I can see how you might want to wait for attached to be successful before loading your stream, the real issue comes when you want to reattach for some reason because you don't need to call loadSource in that case. Also if you want to load something new you should be able to just call loadSource, but you could not in previous viersions without the detach and attach, so we do it for you, but that's where the recursive problem can surface if you do this on attached.

robwalch pushed a commit that referenced this issue Apr 12, 2021
…e URL has changed, and source buffer types are set

Resolves #3732
@robwalch
Copy link
Collaborator

robwalch commented Apr 12, 2021

HI @rchl / cc @MasterEvilAce,

I've reworked #3754 so that loadSource does not reattach unless the URL has changed and SourceBuffers are configured (which happens after ATTACHED and the manifest is loaded). This prevents the recursive behavior reported in this issue, and should eliminate the additional attach you were seeing in the first solution:

https://deploy-preview-3754--hls-js-dev.netlify.app/demo/

If you could, please give it go and let me know if everything looks OK. Thanks!

(the preview URL is the same so you can see the fix in the same sandbox app shared earlier https://codesandbox.io/s/hls-v1-bug-try-fix-9wr6b?file=/index.html)

@rchl
Copy link
Author

rchl commented Apr 12, 2021

Looks good. Seeing only one MEDIA_ATTACHED and MANIFEST_PARSED.

Thanks!

@robwalch robwalch added the Regression A bug introduced in a recent release label Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Regression A bug introduced in a recent release
Projects
Release Planning and Backlog
  
Top priorities
Development

Successfully merging a pull request may close this issue.

3 participants