Set video aspect on initial creation

Previously on first start of a video the aspect ratio
was not correct (annoying on a 18:9 phone as
it doesn't match the usual 16:9 aspect ratio). So extract
the code into a setupVideoAspectRatio() helper
and call it from surfaceCreated as well.
This commit is contained in:
Dirk Mueller 2018-01-08 11:08:56 +01:00
parent fc4057d2c6
commit 32215ffc28
1 changed files with 14 additions and 9 deletions

View File

@ -152,16 +152,9 @@ public class VideoplayerActivity extends MediaplayerActivity {
@Override
protected void onAwaitingVideoSurface() {
setupVideoAspectRatio();
if (videoSurfaceCreated && controller != null) {
Log.d(TAG, "Videosurface already created, setting videosurface now");
Pair<Integer, Integer> videoSize = controller.getVideoSize();
if (videoSize != null && videoSize.first > 0 && videoSize.second > 0) {
Log.d(TAG, "Width,height of video: " + videoSize.first + ", " + videoSize.second);
videoview.setVideoSize(videoSize.first, videoSize.second);
} else {
Log.e(TAG, "Could not determine video size");
}
controller.setVideoSurface(videoview.getHolder());
}
}
@ -199,6 +192,18 @@ public class VideoplayerActivity extends MediaplayerActivity {
videoControlsHider.start();
}
private void setupVideoAspectRatio() {
if (videoSurfaceCreated && controller != null) {
Pair<Integer, Integer> videoSize = controller.getVideoSize();
if (videoSize != null && videoSize.first > 0 && videoSize.second > 0) {
Log.d(TAG, "Width,height of video: " + videoSize.first + ", " + videoSize.second);
videoview.setVideoSize(videoSize.first, videoSize.second);
} else {
Log.e(TAG, "Could not determine video size");
}
}
}
private void toggleVideoControlsVisibility() {
if (videoControlsShowing) {
getSupportActionBar().hide();
@ -247,7 +252,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
Log.e(TAG, "Couldn't attach surface to mediaplayer - reference to service was null");
}
}
setupVideoAspectRatio();
}
@Override