Omkar Jadhav
Omkar Jadhav

Reputation: 504

ExoPlayer in Android TV plays video in portrait mode instead of landscape

We are using ExoPlayer to play m3u8 files (stream) on Android TV. The streaming is working fine, but the video plays in portrait mode (even if the video is shot in landscape). Looks like some issue with orientation of the android TV instead of aspect ratio.

private fun initializePlayer() {

    if(mPlayer == null) {

        playerView = activity!!.findViewById<SimpleExoPlayerView>(R.id.texture_view)
       // playerView!!.setControllerVisibilityListener(this)
        playerView!!.requestFocus()
        val bandwidthMeter = DefaultBandwidthMeter()
        val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory(bandwidthMeter)
        mTrackSelector = DefaultTrackSelector(videoTrackSelectionFactory)

        mPlayer = ExoPlayerFactory.newSimpleInstance(activity, mTrackSelector)
        playerView!!.player= mPlayer

        mPlayerAdapter = LeanbackPlayerAdapter(activity, mPlayer, UPDATE_DELAY)
        mPlayerGlue = VideoPlayerGlue(activity!!, mPlayerAdapter!!)
        mPlayerGlue!!.host = VideoSupportFragmentGlueHost(this)
        mPlayerGlue!!.playWhenPrepared()
        play(s1)
    }
}

Commenting these lines :

mPlayerAdapter = LeanbackPlayerAdapter(activity, mPlayer, UPDATE_DELAY)
mPlayerGlue = VideoPlayerGlue(activity!!, mPlayerAdapter!!)
mPlayerGlue!!.host = VideoSupportFragmentGlueHost(this)
mPlayerGlue!!.playWhenPrepared()

Plays the video in landscape but the player controls are hidden and it only plays the lowest quality of the video. Please help us with this.

Upvotes: 6

Views: 1781

Answers (2)

GunSky7
GunSky7

Reputation: 25

As far i know, exoplayer will generate its size based on texture view size. So try to programmatically resize your texture view by

playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);

and also try to resize your player programmatically

mPlayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);

Hope this will help.

Upvotes: 0

Andy Jazz
Andy Jazz

Reputation: 58553

Metadata of the MP4 video contains a property called Rotation=90° but it's ignored by the ExoPlayer. To fix it you need to inject this Java function into your code:

void onVideoSizeChanged(int width, 
                        int height, 
                        int unappliedRotationDegrees, // 90° or 270°
                      float pixelWidthHeightRatio);

This allows an application using TextureView to easily apply the rotation by making the appropriate call to TextureView.setTransform. Note that on Lollypop+ unappliedRotationDegrees will always be equal to 0.

You can find this function on a line #74 at MediaCodecVideoTrackRenderer page of GitHub.

If the above-mentioned method doesn't work for you, you may find another remedy in Rotation Issue #91 post on a GitHub.

Upvotes: 1

Related Questions