This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[video_player] Passing http headers to file constructor #6213
Closed
abdelaziz-mahdy
wants to merge
51
commits into
flutter:main
from
abdelaziz-mahdy:passing-httpHeaders-to-file-constructor
Closed
Changes from 47 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
f31ecb0
Upgraded to exoPlayer 2.17.0
abdelaziz-mahdy e708902
fixed (onPlayerError override not working)
abdelaziz-mahdy a5f8e6f
formatted code
abdelaziz-mahdy c859b17
changed changelog and pubspec
abdelaziz-mahdy 1b7a127
Fix CHANGELOG
stuartmorgan-g aa296a4
Merge branch 'main' into main
stuartmorgan-g 012c42f
Update version
stuartmorgan-g a23cc11
added http headers to file constuctor
abdelaziz-mahdy d38bddc
removed if condition
abdelaziz-mahdy afee9ba
Merge branch 'main' of https://github.com/flutter/plugins into passin…
abdelaziz-mahdy 00d26c0
versions updates,formating
abdelaziz-mahdy cbfb811
fixed missing value in constructor
abdelaziz-mahdy 51659d1
added print to test value
abdelaziz-mahdy 2dba163
testing prints
abdelaziz-mahdy 99f86bb
new print
abdelaziz-mahdy bd4c6ce
importing log
abdelaziz-mahdy 22c0d39
to string added
abdelaziz-mahdy a8ff4f5
testing new logic
abdelaziz-mahdy f8499c2
removed unused code
abdelaziz-mahdy daf919f
trying new logic
abdelaziz-mahdy 95bb752
removed new keyword
abdelaziz-mahdy f5288da
new logic applied
abdelaziz-mahdy cae6544
uri added again
abdelaziz-mahdy c333d43
added option to allow diffrent user agent
abdelaziz-mahdy 5eb2a37
wrong declration fixed
abdelaziz-mahdy d164e2d
string for user agent
abdelaziz-mahdy 03e8e6b
fixed map error
abdelaziz-mahdy fa5c660
formating and changelog changes
abdelaziz-mahdy 385c879
goes to normal httpDataSourceFactory incase no http header is defined
abdelaziz-mahdy 24f3c20
Merge https://github.com/zezo357/plugins into passing-httpHeaders-to-…
abdelaziz-mahdy 6c3caf0
added tests
abdelaziz-mahdy 892c51c
formatting
abdelaziz-mahdy 801f15b
Update packages/video_player/video_player/CHANGELOG.md
abdelaziz-mahdy f247b0d
Update packages/video_player/video_player/lib/video_player.dart
abdelaziz-mahdy 9946c86
Update packages/video_player/video_player_android/CHANGELOG.md
abdelaziz-mahdy 019a6b7
formatting/ and comments
abdelaziz-mahdy 11c4b4e
fixed error
abdelaziz-mahdy 021d0e9
Merge remote-tracking branch 'upstream/main' into passing-httpHeaders…
camsim99 49eed6a
Formatting
camsim99 46120a9
Fix merge
camsim99 e15b3a5
Undo formatting changes
camsim99 c1732d5
Undo webview change
camsim99 f6aea05
Merge remote-tracking branch 'upstream/main' into passing-httpHeaders…
camsim99 1f0c702
Undo formatting changees for clarity
camsim99 315d460
Add tests
camsim99 abb9037
fixed dart test
abdelaziz-mahdy cb6e378
formatting
abdelaziz-mahdy 1d15a23
updated change logs
abdelaziz-mahdy 55923d9
updated version
abdelaziz-mahdy 4ce6747
removed next since new version exists
abdelaziz-mahdy bac9c75
fixed spacing
abdelaziz-mahdy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,10 +56,14 @@ final class VideoPlayer { | |
|
|
||
| private final EventChannel eventChannel; | ||
|
|
||
| private final String USER_AGENT = "User-Agent"; | ||
|
|
||
| @VisibleForTesting boolean isInitialized = false; | ||
|
|
||
| private final VideoPlayerOptions options; | ||
|
|
||
| private DefaultHttpDataSource.Factory httpDataSourceFactory = new DefaultHttpDataSource.Factory(); | ||
|
|
||
| VideoPlayer( | ||
| Context context, | ||
| EventChannel eventChannel, | ||
|
|
@@ -73,23 +77,11 @@ final class VideoPlayer { | |
| this.options = options; | ||
|
|
||
| ExoPlayer exoPlayer = new ExoPlayer.Builder(context).build(); | ||
|
|
||
| Uri uri = Uri.parse(dataSource); | ||
| DataSource.Factory dataSourceFactory; | ||
|
|
||
| if (isHTTP(uri)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zezo357 I am ready to add tests but I have some follow up questions first to make sure I understand the change.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1-If not http all functions will work and it's the main fix since when playing a m3u8 file it's not http 2- user agent should be added to the http headers If the user wants it (it's needed because some hosts do not allow the default user agent) |
||
| DefaultHttpDataSource.Factory httpDataSourceFactory = | ||
| new DefaultHttpDataSource.Factory() | ||
| .setUserAgent("ExoPlayer") | ||
| .setAllowCrossProtocolRedirects(true); | ||
|
|
||
| if (httpHeaders != null && !httpHeaders.isEmpty()) { | ||
| httpDataSourceFactory.setDefaultRequestProperties(httpHeaders); | ||
| } | ||
| dataSourceFactory = httpDataSourceFactory; | ||
| } else { | ||
| dataSourceFactory = new DefaultDataSource.Factory(context); | ||
| } | ||
| buildHttpDataSourceFactory(httpHeaders); | ||
| DataSource.Factory dataSourceFactory = | ||
| new DefaultDataSource.Factory(context, httpDataSourceFactory); | ||
|
|
||
| MediaSource mediaSource = buildMediaSource(uri, dataSourceFactory, formatHint, context); | ||
|
|
||
|
|
@@ -106,20 +98,29 @@ final class VideoPlayer { | |
| EventChannel eventChannel, | ||
| TextureRegistry.SurfaceTextureEntry textureEntry, | ||
| VideoPlayerOptions options, | ||
| QueuingEventSink eventSink) { | ||
| QueuingEventSink eventSink, | ||
| DefaultHttpDataSource.Factory httpDataSourceFactory) { | ||
| this.eventChannel = eventChannel; | ||
| this.textureEntry = textureEntry; | ||
| this.options = options; | ||
| this.httpDataSourceFactory = httpDataSourceFactory; | ||
|
|
||
| setUpVideoPlayer(exoPlayer, eventSink); | ||
| } | ||
|
|
||
| private static boolean isHTTP(Uri uri) { | ||
| if (uri == null || uri.getScheme() == null) { | ||
| return false; | ||
| @VisibleForTesting | ||
| public void buildHttpDataSourceFactory(@NonNull Map<String, String> httpHeaders) { | ||
| final boolean httpHeadersNotEmpty = httpHeaders != null && !httpHeaders.isEmpty(); | ||
| final String userAgent = | ||
| httpHeadersNotEmpty && httpHeaders.containsKey(USER_AGENT) | ||
| ? httpHeaders.get(USER_AGENT) | ||
| : "ExoPlayer"; | ||
|
|
||
| httpDataSourceFactory.setUserAgent(userAgent).setAllowCrossProtocolRedirects(true); | ||
|
|
||
| if (httpHeadersNotEmpty) { | ||
| httpDataSourceFactory.setDefaultRequestProperties(httpHeaders); | ||
| } | ||
| String scheme = uri.getScheme(); | ||
| return scheme.equals("http") || scheme.equals("https"); | ||
| } | ||
|
|
||
| private MediaSource buildMediaSource( | ||
|
|
@@ -149,13 +150,11 @@ private MediaSource buildMediaSource( | |
| switch (type) { | ||
| case C.CONTENT_TYPE_SS: | ||
| return new SsMediaSource.Factory( | ||
| new DefaultSsChunkSource.Factory(mediaDataSourceFactory), | ||
| new DefaultDataSource.Factory(context, mediaDataSourceFactory)) | ||
| new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mediaDataSourceFactory) | ||
| .createMediaSource(MediaItem.fromUri(uri)); | ||
| case C.CONTENT_TYPE_DASH: | ||
| return new DashMediaSource.Factory( | ||
| new DefaultDashChunkSource.Factory(mediaDataSourceFactory), | ||
| new DefaultDataSource.Factory(context, mediaDataSourceFactory)) | ||
| new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mediaDataSourceFactory) | ||
| .createMediaSource(MediaItem.fromUri(uri)); | ||
| case C.CONTENT_TYPE_HLS: | ||
| return new HlsMediaSource.Factory(mediaDataSourceFactory) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.