-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Switching between HLS streams without buffering #7771
Comments
That if added will be a nice featuring... And technically can almost happen take a look at this On that video a In 5 seconds I change the stream without load a There is a moment of black screen but technically in most devices you don't notice it most of the time (very slow device you may notice it more), here is the app try it https://play.google.com/store/apps/details?id=com.fgl27.twitch And the only thing I do is what demo app already does here ExoPlayer/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java Line 349 in 5bfad37
More precisely this line changes the media source : ExoPlayer/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java Line 399 in 5bfad37
What is that exactly? if the player is not null it is already playing something, just change the In order to not freeze the UI you can download and parse the HLS information then create a media source all on a background thread then send it when is done to UI thread to update the player. Any way that is a help, but not what you ask. Hope a feature like this is added on the future as will improve even further my process and give you what you really ask. |
I assume, when you say HLS and 'changing TV channels' then you are talking about live streams. If this is the case I actually think the use case you are talking about is probably not super easy to implement without buffering or it requires two player instances. So you can start loading and preparing the second live stream while still playing the first one, once the second player transitions to 'STATE_READY', you can switch the surface to the second player that starts rendering immediately. |
On my side of things not in relation to who open the issue...
Yes live stream, as they are live doesn't wort to have a list of
5 seconds there is on the video I share... So no need for two player just one and do the background thread I explain after.
|
Is technically a simple process in relation to use two players, I'm just a casual developer and can do it very simply so anyone can. |
@marcbaechinger thanks for your reply, what exactly do you mean by switching surface between the two players? We are currently using PlayerView as a holder for the player. |
You can use the method |
@marcbaechinger thanks, we used a creation of another player that would be used when switching channels, and it is working pretty ok, but we are experiencing issues with buffering: setting of the player (inside Player.STATE_READY case of onPlayerStateChanged())-
setting of hls stream(source is HlsMediaSource) -
the issue: what we noticed is that without setting player.seekTo(0), the stream would load faster, but buffer health would be terrible, otherwise, the stream loads slower, but buffer is okay. Sometimes, the new stream would get stuck in buffering and would never be played, are we making any mistakes in setting the player and/or stream? |
I think these are live streams so with seeking to 0 you are not seeking to the default position. For live streams the default position is somewhere close to the live edge, while 0 is at the beginning of the live window. Assuming the player in the second code snippet has not been used, you override the default position with the
That makes the player figure out the default position of the stream. Please also check the JavaDoc of the Timeline class which gives you some more details about the window and the default position for different types of streams. When you refer to 'buffer health' you probably mean that you run into problems with BehindLiveWindow exceptions. This would match to to I'm not quite sure why the stream loads slower for Feel free to send me the logcat output of |
@marcbaechinger once again, thanks for the answer and sharing your knowledge. We switched to using
Also, I forgot to mention, setting of the HlsMediaSource is done in the following way:
This is the log that i get when the stream is loading slower, or is buffering between switching, our code is setup that in the case of 404 error, we retry the stream (this type of output and behavior isn't constant, it happens from time to time), this output is from the second i start the switch onwards:
and later the stream is set. |
Seems like there is a problem on the server side then. Are you controlling the server side? It seems like there are segments in the HLS playlist which do not exist on the server and result in a 404. It would make sense that the player remains in the buffering state as long as the player retries. There is not much the player can do when hitting a 404 on the server for a segment thats declared in the HLS playlist. |
you were right, there were some issues on the server side of the project, but we got that fixed, and still we have some trouble when switching streams, longer waiting period, sometimes getting stuck in state idle, this primarily happens in faster switching.. could the issue be that we are only using one PlayerView?
|
Not sure but I don't think this has to do with using a single Can you please start your app with the |
I have sent an email to the above address, hope to be hearing from you soon. |
I think this is not a complete bug report. It only contains the window manager parts of it? This link describes how to capture a bug report. Roughly you can do a
Can you check and probably send the email again with a full bug report? |
Yeah, i made a mistake, i sent the full report again, hope this one will clear the situation |
Thanks! When looking into the bug report I can't really see playback of ExoPlayer I'm afraid. I'd expect at least a line containing ExoPlayerLib which is printed in INFO level. I can't find that line. It seems that the log starts at 15:29:19.011 and ends at 15:31:07.925 so it contains only about 1 and a half minute of logs. which is unusual. However, the second email you sent has the logcat you commented on. There we can still see 404's and Can you try to repro the behaviour without hitting streams that return a 404? Like disabling 404-streams in the list of channels and then quickly switch between channels that are available? If you are looking into diagnosing yourself as you do according to what you write in the email and I encourage you to do so :), then I would suggest that you add an |
When I switch the channels normally (not in full screen, we have a list feature, like in an leanback app, where you can watch the livestream) there is never a unexpected end of stream, nor 404 exceptions. This is what confuses me, this behavior is only "available" when switching channels rapidly, and non-stop setting of the new stream between the two players. Here is the |
The log shows three different errors. There is one single error regarding media codec which I leave aside. All the other errors are either a HTTP 404 or an 'unexpected end of stream'. The 404 is generated as a result of an http connection which has been opened. The server accepts the connection receives a GET request and then delivers back a 404. From the point of view of the client this is working as intended. No network or any other problems below and including the application protocol http with which the server signals that the given file is not found. The other exception is reporting an unexpected end of stream:
Please note that the error is reported by the okhttp network stack. ExoPlayer does only propagate that error. The unexpected end of stream is a consequence of the server closing the connection when data is requested. Hard to say why. Probably the server reports a incorrect content-length or similar. Technically, these are network errors and ExoPlayer can not really do much when receiving these. I would try to diagnose what is happening on the server side: With an HLS live stream, the player first request a playlist. A text file which tells the player what media chunks are available on the server. So a first interesting bit of information would be whether the network error happens when the playlist is requested or when a media file which is referenced in that playlist is requested. The server logs will tell. For a live stream, the playlist file references a given number of chunks which represent the dynamically moving live window. Chunks of media of a given duration which are available on the server for a certain duration only. It needs to make sure that these chunks declared in the playlist are available on the server. Check what is EXT-X-START in the playlist which is the default position you seek to (C.TIME_UNSET). If there is not EXT-C-START it takes the third segment from the end of the live window. You or your backend team should see these 404s and the unexpected end of stream in the logs on the server side as well. You will then be able to diagnose what files have been requested and why it fails. I really think removing these network failures are at the heart of this issue. From what I can see in the logs, there is nothing which makes me think that the player is mistaken in some logic because these errors are happening on the network layer. |
[REQUIRED] Searched documentation and issues
#677
#3327
[REQUIRED] Question
I'm currently working on a project that implements the usage of ExoPlayer in our Tv Application. Our only focus is on HLS streaming. Application has a list of channels that are shown and can be viewed in full screen. What are users are currently demanding is implementation of the next feature: when a channel is changed, they would want the transition to be smooth. By that, they mean that we never see the buffering of the next stream's content.
The desired flow would be:
The text was updated successfully, but these errors were encountered: