androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.69k stars 404 forks source link

HTTP 301-302 forwarding fails for .m3u8 files if extension of original is incorrect. #1699

Open w3woody opened 2 months ago

w3woody commented 2 months ago

Version

Media3 1.4.1

More version details

I have also been able to reproduce this on the current 'main' branch.

Devices that reproduce the issue

Google Pixel 5 running Android Version 14.

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

No

Reproduction steps

Create a new video player. Attempt to play a video from https://c1m.co/test.php (this is my personal test server, and I'll leave the file up). The file will return a 302 forward request to https://test-streams.mux.dev/tos_ismc/main.m3u8 Playback will fail with an error "ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED"

If you replace the URL with the final destination (https://test-streams.mux.dev/tos_ismc/main.m3u8), the video will play back just fine.

Discussion

I spent some time going through the ExoPlayer code. It appears what is happening is that after the forwarding is followed DefaultHttpDataSource, the original URL is used (...test.php) to determine the file type of the video file to play back. As it does not end with m3u8, ExoPlayer decides it must be a movie and attempts to read the binary header to determine the type of payback file.

Further, the ExoPlayer code appears to discard (or never use) the mime type returned with the forwarded file.

I have been able to work around this issue by creating a helper class that does a 'HEAD' request to get the final destination after 301/302 forwarding, as well as the returned mime type, but it seems ExoPlayer should be able to do this 'automagically.'

Expected result

The video at the URL forwarded from 'https://c1m.co/test.php' be identified correctly and played properly if it is an .m3u8 file.

Actual result

Playback will fail with an error "ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED"

Media

https://c1m.co/test.php

Bug Report

w3woody commented 2 months ago

Sample application which can reproduce the issue (consisting of one .java file that kicks off the player) attached.

TestExoPlayer.zip

To test, compile and run. You can see the failure by uncommenting line 34 in VideoActivity.java; you can see it work successfully by commenting out line 34 and uncommenting line 33.

marcbaechinger commented 2 months ago

but it seems ExoPlayer should be able to do this 'automagically.'

This isn't the case I'm afraid. Setting the mime type in the media item should do the trick.

Please see the docs around non-standard file extensions: https://developer.android.com/media/media3/exoplayer/media-items#handling-non-standard