-
Notifications
You must be signed in to change notification settings - Fork 9.8k
video_player: use exoplayer for better video compatibility #597
Conversation
- remove unused imports - fix formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, much appreciated. Can I ask you to address the white space issues? That would make it much easier to review the actual code changes. Thanks!
dependencies { | ||
implementation 'com.google.android.exoplayer:exoplayer-core:2.8.0' | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please this remove empty line.
implementation 'com.google.android.exoplayer:exoplayer-core:2.8.0' | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and add one at the end of the file.
result.error("VideoError", "IOError when initializing video player " + e.toString(), null); | ||
} | ||
} | ||
private static class VideoPlayer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reduce indentation to two spaces to make the real diff stand out.
gradle line fixes
Done - Readability seems better now. |
@jonasbark Thanks! The formatter CI job is still complaining about white space. The CONTRIBUTING.md file details how to get the Java formatter running on your machine. |
pub global run flutter_plugin_tools format --plugins video_player
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM so far. I'll do some on-device testing and see if anything shows up.
packages/video_player/CHANGELOG.md
Outdated
@@ -1,3 +1,7 @@ | |||
## 0.5.5 | |||
|
|||
* Android: use ExoPlayer instead of MediaPlayer for better video compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"better video compatibility" => "better video format support"?
Please end line with a period.
public void onLoadingChanged(final boolean isLoading) { | ||
|
||
if (!isLoading) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove empty lines inside methods.
new MediaPlayer.OnCompletionListener() { | ||
@Override | ||
public void onCompletion(MediaPlayer mediaPlayer) { | ||
exoPlayer.addListener(new EventListener() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe subclass DefaultEventListener
to avoid the empty methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea - I implemented the changes based on your other suggestions as well and pushed the commit.
@@ -337,6 +320,9 @@ private void onMethodCall(MethodCall call, Result result, long textureId, VideoP | |||
videoPlayers.remove(textureId); | |||
result.success(null); | |||
break; | |||
case "orientation": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Dart side does not call this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, that was a leftover. Will remove it.
exoPlayer.setPlayWhenReady(true); | ||
|
||
exoPlayer.addListener( | ||
new EventListener() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you missed my earlier comment here (we had a mid-air collision with your white space changes): please consider subclassing DefaultEventListener
instead to avoid the empty methods.
- remove setVolume(0.0) call when loading is finished - adjust changelog
The example video takes a long time (order of 30 seconds) to show up, and when it does, it's several seconds into the playback. Are we starting the player correctly? For the butterfly video, I get one of these on each loop:
|
@mravn-google I've noticed that the actual code in the example is, I would say, "accidentally", working due to a series of possibly random conditions:
|
Indeed - I didn't catch that during testing. I pushed the necessary changes. Initialization should be sent already when the playback state changes to Player.STATE_READY. Previously it was sent only when the video has finished being fully loaded. Nothing wrong on the Dart side imo. Regarding the ACodec output. As it's marked as Log.INFO I wouldn't consider this an error. |
@sroddy are you taking about the example in the |
|
@sroddy regarding 2.): with the fixed commits the example videos will start right away. No need to tap on a play button. |
packages/video_player/pubspec.yaml
Outdated
@@ -2,8 +2,8 @@ name: video_player | |||
description: Flutter plugin for displaying inline video with other Flutter | |||
widgets on Android and iOS. | |||
author: Flutter Team <flutter-dev@googlegroups.com> | |||
version: 0.5.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make this a 0.6.0 to allow for patches to the version of the plugin that still uses MediaPlayer
.
Map<String, Object> reply = new HashMap<>(); | ||
reply.put("textureId", textureEntry.id()); | ||
result.success(reply); | ||
} | ||
|
||
@SuppressWarnings("deprecation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no ExoPlayer equivalent of the code below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There actually is. I thought this was just a workaround to ensure proper audio playback on older Android devices. I readded this.
@sroddy I see your point now! The video will not show the first frame before it actually starts playing. That should probably be fixed... |
Does anyone have an idea how to approach this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Map<String, Object> reply = new HashMap<>(); | ||
reply.put("textureId", textureEntry.id()); | ||
result.success(reply); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
private static void setAudioAttributes(MediaPlayer mediaPlayer) { | ||
private static void setAudioAttributes(SimpleExoPlayer mediaPlayer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mediaPlayer
=> exoPlayer
@jonasbark The initialization issue is not really related to your changes, and we are working to fix it in a separate PR. |
@jonasbark It appears we've accrued a merge conflict while waiting for CI to go green. Care to rebase and bump the version number? |
…oplayer # Conflicts: # packages/video_player/CHANGELOG.md # packages/video_player/pubspec.yaml
Done |
@jonasbark Thanks a lot. I'll land on green. |
Published. |
@jonasbark Great work. Just FYI .m3u8 format is not supported I've raised an issue for that. Will see if I can tackle it. flutter/flutter#18328 |
Hi, dose it support RTMP playback, it seems not i get the following exception though,
|
@uwejan afaik exoplayer2 supports rtmp via plugin: https://github.com/google/ExoPlayer/tree/dev-v2-r2.8.4/extensions/rtmp so it's not supported ootb |
@uwejan I have added m3u8 and dash support in this PR. https://github.com/flutter/plugins/pull/613/files |
The default Android implementation using the
MediaPlayer
had different playback / codec problems on different devices. We mostly saw problems with a few Samsung phones.By using the
ExoPlayer
library playback works fine on all devices we tested so far.