Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[video_player] Fix aspect ratio #690

Merged
merged 48 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3dd5099
* Added access to the video rotation in degrees (rotationDegrees). Po…
recastrodiaz Jul 28, 2018
bb8e0b5
Bugfix: rotated videos will now be displayed with the correct aspect …
recastrodiaz Jul 28, 2018
f385849
Fix format. Use clang-format-5.0 instead of clang-format (7.0)
recastrodiaz Jul 28, 2018
7943a8f
Fix format. Remove spurious extra line.
recastrodiaz Jul 28, 2018
9a7a974
Fix race condition in video_player that prevented some videos from be…
recastrodiaz Jul 29, 2018
230c7e0
Merge branch 'video_player_aspectratio' into develop
recastrodiaz Jul 29, 2018
0332538
Ensure videos are not upside down nor streteched when using the video…
recastrodiaz Aug 13, 2018
7ef3092
Ensure videos are not upside down nor streteched when using the video…
recastrodiaz Aug 13, 2018
27f55da
Merge branch 'master' into video_player_aspectratio
recastrodiaz Aug 13, 2018
2238d06
Merge remote-tracking branch 'upstream/master' into video_player_fix_…
recastrodiaz Aug 13, 2018
9e74b42
Add support for 'sendInitialized' flutter event that fixes race condi…
recastrodiaz Aug 13, 2018
d0ecc95
Merge branch 'video_player_aspectratio' into develop
recastrodiaz Aug 14, 2018
f390cc2
Merge branch 'video_player_fix_race_condition' into develop
recastrodiaz Aug 15, 2018
fd5c298
Ensure with and height of a video is given after rotation. i.e. If vi…
recastrodiaz Aug 15, 2018
f0ade3c
- Merge fix_race_condition branch so sendInitialized is only sent onc…
recastrodiaz Aug 15, 2018
c55c5c2
Sometimes, the preferredTransformed returned by the videoTrack does n…
recastrodiaz Aug 16, 2018
65e19ff
Merge remote-tracking branch 'upstream/master' into phAsset
recastrodiaz Aug 22, 2018
0943513
- Removed support for phasset:// files. Support for phAssets will be …
recastrodiaz Aug 22, 2018
ed6de31
Merge branch 'master' of github.com:flutter/plugins into video_player…
recastrodiaz Sep 11, 2018
0490800
Remove bad merge line from CHANGELOG.md
recastrodiaz Sep 11, 2018
9b21739
Format files
recastrodiaz Sep 11, 2018
10df65e
Ensure width/height is properly set when videos are rotated
recastrodiaz Sep 11, 2018
57a6540
Ensure that when the aspectRatio getter is called on a video controll…
recastrodiaz Sep 12, 2018
fcafe84
Merge remote-tracking branch 'upstream/master' into video_player_aspe…
recastrodiaz Sep 12, 2018
a57cf89
Remove unused variable
recastrodiaz Sep 12, 2018
7796db7
- Removed dead code and unused comments
recastrodiaz Sep 22, 2018
291ff1e
Fix style
recastrodiaz Sep 22, 2018
74b5d76
Fix style
recastrodiaz Sep 22, 2018
8740483
Merge remote-tracking branch 'upstream/master' into video_player_aspe…
recastrodiaz Oct 22, 2018
a9cf432
Merge branch 'master' of github.com:flutter/plugins into video_player…
recastrodiaz Nov 1, 2018
42ad92f
Add missing space to toString method
recastrodiaz Nov 1, 2018
96afebc
Merge branch 'master' of github.com:flutter/plugins into video_player…
recastrodiaz Nov 16, 2018
9d7f57c
- Removed _isInitialized = true in swithc case AVPlayerItemStatusRead…
recastrodiaz Nov 16, 2018
4be9e38
- Revert back to original _isInitialized logic
recastrodiaz Nov 16, 2018
3cba0f6
Remove dispatch_async as it is no longer needed. c.f. https://github.…
recastrodiaz Nov 19, 2018
6e2d195
- Remove catchError in README
recastrodiaz Nov 20, 2018
9b622ed
- Use clang-format 8.0
recastrodiaz Nov 20, 2018
de58514
Merge branch 'master' of github.com:recastrodiaz/plugins into video_p…
recastrodiaz Nov 20, 2018
a0d2b25
Remove unused variable
recastrodiaz Nov 20, 2018
664aab7
Remove variable rotationDegrees
recastrodiaz Nov 20, 2018
b5b87e8
-Remove extra empty new lines
recastrodiaz Nov 20, 2018
d589ee5
Merge remote-tracking branch 'upstream/master' into video_player_aspe…
recastrodiaz Nov 22, 2018
7e265a5
Merge remote-tracking branch 'upstream/master' into video_player_aspe…
recastrodiaz Jan 6, 2019
232fec9
Merge remote-tracking branch 'upstream/master' into video_player_aspe…
recastrodiaz Jan 18, 2019
8d571fb
video_player examples:
recastrodiaz Jan 23, 2019
6792cd9
Merge remote-tracking branch 'upstream/master' into video_player_aspe…
recastrodiaz Jan 24, 2019
40f756c
- Bump video_player version to 0.9.0
recastrodiaz Jan 24, 2019
055cb53
- Bump plugin to 0.9.0 (not just the changelog)
recastrodiaz Jan 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/image_picker/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,9 @@ class AspectRatioVideoState extends State<AspectRatioVideo> {
@override
Widget build(BuildContext context) {
if (initialized) {
final Size size = controller.value.size;
return Center(
child: AspectRatio(
aspectRatio: size.width / size.height,
aspectRatio: controller.value?.aspectRatio,
dnfield marked this conversation as resolved.
Show resolved Hide resolved
child: VideoPlayer(controller),
),
);
Expand Down
5 changes: 5 additions & 0 deletions packages/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.8.1

* Fixed the aspect ratio and orientation of videos. Videos are now properly displayed when recorded
in portrait mode both in iOS and Android.

## 0.8.0

* Android: Upgrade ExoPlayer to 2.9.1
Expand Down
27 changes: 13 additions & 14 deletions packages/video_player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,12 @@ class VideoApp extends StatefulWidget {

class _VideoAppState extends State<VideoApp> {
VideoPlayerController _controller;
bool _isPlaying = false;

@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_20mb.mp4',
)
..addListener(() {
final bool isPlaying = _controller.value.isPlaying;
if (isPlaying != _isPlaying) {
setState(() {
_isPlaying = isPlaying;
});
}
})
'http://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4')
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
Expand All @@ -91,15 +81,24 @@ class _VideoAppState extends State<VideoApp> {
: Container(),
),
floatingActionButton: FloatingActionButton(
onPressed: _controller.value.isPlaying
? _controller.pause
: _controller.play,
onPressed: () {
_controller.value.isPlaying
? _controller.pause()
: _controller.play();
setState(() {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we calling setState empty here? Can we either move the lines above this to the closure for setState, or comment on the unusual use of setState here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move them inside the setState. We need setState as otherwise the play/pause button UI does not get updated.

},
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
),
),
);
}

@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Player.DefaultEventListener;
import com.google.android.exoplayer2.SimpleExoPlayer;
Expand Down Expand Up @@ -51,6 +52,8 @@

public class VideoPlayerPlugin implements MethodCallHandler {

private static final String TAG = "VideoPlayerPlugin";

private static class VideoPlayer {

private SimpleExoPlayer exoPlayer;
Expand Down Expand Up @@ -220,9 +223,19 @@ private void sendInitialized() {
Map<String, Object> event = new HashMap<>();
event.put("event", "initialized");
event.put("duration", exoPlayer.getDuration());

if (exoPlayer.getVideoFormat() != null) {
event.put("width", exoPlayer.getVideoFormat().width);
event.put("height", exoPlayer.getVideoFormat().height);
Format videoFormat = exoPlayer.getVideoFormat();
int width = videoFormat.width;
int height = videoFormat.height;
int rotationDegrees = videoFormat.rotationDegrees;
// Switch the width/height if video was taken in portrait mode
if (rotationDegrees == 90 || rotationDegrees == 270) {
width = exoPlayer.getVideoFormat().height;
height = exoPlayer.getVideoFormat().width;
}
event.put("width", width);
event.put("height", height);
}
eventSink.success(event);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/video_player/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void main() {
Column(
children: <Widget>[
NetworkPlayerLifeCycle(
'http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_20mb.mp4',
'http://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4',
(BuildContext context, VideoPlayerController controller) =>
AspectRatioVideo(controller),
),
Expand All @@ -395,7 +395,7 @@ void main() {
],
),
NetworkPlayerLifeCycle(
'http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_20mb.mp4',
'http://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4',
(BuildContext context, VideoPlayerController controller) =>
AspectRatioVideo(controller),
),
Expand Down
Loading