Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 950
Omkar Jadhav Avatar asked Aug 21 '18 11:08

Omkar Jadhav


1 Answers

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.

like image 77
Andy Jazz Avatar answered Nov 15 '22 10:11

Andy Jazz