android4.4で動画再生すると、90度回転して再生されます。
android8は正常に再生されます。
exoplayerのバージョンは2.11.4です。
com.google.android.exoplayer:exoplayer-core:2.11.4
android4.4で正常に再生するにはどうすればよろしいでしょうか?
アドバイスをよろしくお願いいたします。
public class VideoView extends FrameLayout {
private HandlerWrapper mHandler;
private Uri mUri;
private SurfaceView mSurfaceView;
private SimpleExoPlayer mMediaPlayer;
public VideoView(Context context) {
super(context);
init(null, 0);
}
public VideoView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs, 0);
}
public VideoView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs, defStyle);
}
@Override
protected void onDetachedFromWindow() {
releaseMediaPlayer();
super.onDetachedFromWindow();
}
public void setHandler(HandlerWrapper handler) {
mHandler = handler;
}
public void setUri(Uri uri) {
mUri = uri;
}
public void play() {
if (mMediaPlayer == null)
return;
mMediaPlayer.setPlayWhenReady(true);
}
public void pause() {
if (mMediaPlayer == null)
return;
mMediaPlayer.setPlayWhenReady(false);
}
public void seekTo(long position) {
if (mMediaPlayer == null)
return;
mMediaPlayer.seekTo(position);
}
public boolean isPlaying() {
return mMediaPlayer != null &&
mMediaPlayer.getPlaybackState() != Player.STATE_ENDED &&
mMediaPlayer.getPlaybackState() != Player.STATE_IDLE &&
mMediaPlayer.getPlayWhenReady();
}
private void init(AttributeSet attrs, int defStyle) {
mSurfaceView = new SurfaceView(getContext());
mSurfaceView.setZOrderOnTop(true);
addView(mSurfaceView, 1, 1);
mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
DefaultLoadControl loadControl = new DefaultLoadControl.Builder()
.setPrioritizeTimeOverSizeThresholds(false)
.createDefaultLoadControl();
mMediaPlayer = new SimpleExoPlayer.Builder(getContext())
.setLoadControl(loadControl)
.build();
mMediaPlayer.setVideoSurfaceHolder(holder);
Context context = getContext();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context,
Util.getUserAgent(context, context.getPackageName()));
MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(mUri);
mMediaPlayer.addVideoListener(new VideoListener() {
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
layoutSurfaceView(width, height);
}
});
mMediaPlayer.addListener(new EventListener() {
private boolean mReady;
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
}
@Override
public void onIsPlayingChanged(boolean isPlaying) {
}
@Override
public void onPlayerError(ExoPlaybackException error) {
}
});
mMediaPlayer.prepare(videoSource);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
releaseMediaPlayer();
}
});
}
private void releaseMediaPlayer() {
if (mMediaPlayer == null)
return;
mMediaPlayer.release();
mMediaPlayer = null;
}
private void layoutSurfaceView(int width, int height) {
if (mMediaPlayer == null)
return;
float radio = Math.min((float)getWidth() / (float)width, (float)getHeight() / (float)height);
LayoutParams params = (LayoutParams)mSurfaceView.getLayoutParams();
params.width = (int)Math.floor(width * radio);
params.height = (int)Math.floor(height * radio);
params.gravity = Gravity.CENTER;
mSurfaceView.requestLayout();
}
}