video-dev / hls.js

HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
https://hlsjs.video-dev.org/demo
Other
14.9k stars 2.58k forks source link

Is there an end of live stream notification for m3u8 streams? #2363

Closed matrix8369 closed 4 years ago

matrix8369 commented 5 years ago

I am running a livestream in XSplit and loading it into my player through an .m3u8 URL. The livestream runs and I can see it in my player just fine but if I end the stream in XSplit, the player doesn't know the stream is over and never triggers the VideoEnded function in my player code.

I set up the player to spit out every event I could find but the only event that seams to be triggered once the stream is over is the

===Error Event: hlsError=== ===Error Type: mediaError=== ===Error Details: bufferStalledError=== ===Error Fatal: false===

I can't really use this to determine if the livestream is over because it also triggered some times during playback of a running livestream.

Here is the code I am working with currently. P represents the player object, in case the customer has more then 1 player on a page, the code will know what player to effect. The VideoEnded(P) function , when triggered, will switch the P player to the next video in the play list. I don't really see any fatal errors happen if a stream is running ok and the end user stops the live stream.

if (Hls.isSupported()) { P.LiveFeedStreaming = true; console.log('We have a live stream (Desktop, Andriod)'); var video = document.getElementById(P.Guid).getElementsByTagName('video')[0]; P.hls = new Hls(); P.hls.attachMedia(video); console.log("Hls Event"); P.hls.on(Hls.Events.MEDIA_ATTACHED, function () { console.log("video and hls.js are now bound together !"); P.hls.loadSource(VURL); P.hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) { console.log("manifest loaded, found " + data.levels.length + " quality level"); if (P.AutoPlay === true && P.FirstPageLoad === true) { console.log("Auto Play: Livestream"); Play(P, false); P.FirstPageLoad = false; } }); });

P.hls.on(Hls.Events.ERROR, function (event, data) { console.log("============================================"); console.log("===Error: " + event + "==="); console.log("===Error: " + data.type + "==="); console.log("===Error: " + data.details + "==="); console.log("===Error: " + data.fatal + "==="); console.log("============================================"); if (data.details === "bufferStalledError") { console.log("Livestream has ended"); ShowHideBuffer(false, P); P.LiveFeedStreaming = false; P.hls.destroy(); if (P.Playing === true && P.LiveFeed === true) { VideoEnded(P); } } if (data.fatal) { switch (data.type) { case Hls.ErrorTypes.NETWORK_ERROR: console.log("Fatal network error encountered, try to recover"); P.hls.startLoad(); break; case Hls.ErrorTypes.MEDIA_ERROR: console.log("Fatal media error encountered, try to recover"); P.hls.recoverMediaError(); break; default: // cannot recover console.log("Failed to recover stream, trigger Video Ended function"); ShowHideBuffer(false, P); P.LiveFeedStreaming = false; P.hls.destroy(); if (P.Playing === true && P.LiveFeed === true) { VideoEnded(P); } break; } } });

OrenMe commented 5 years ago

An event stream should end with EXT-X-ENDLIST and then you will get a nice ended event from video. See more details here: https://developer.apple.com/documentation/http_live_streaming/example_playlists_for_http_live_streaming/event_playlist_construction

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.