subtitle selection in exoplayer not within screen bounds

144 Views Asked by At

Im trying to develop an android application for TV using exoplayer. Everything works fine in the emulator but when I try to run it on a physical device the problems occurs.

TV is an running android 6 and have a resolution of (3840x2160)

When I press the CC button in the StyledPlayerView controller the subtitles selection goes out of the screen.

Here is my movvieplayer class and xml file

import android.app.Activity;
import android.os.Bundle;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.southpalmresort.sprtv.R;


public class MoviePlayer extends Activity {

    private ExoPlayer player;
    private StyledPlayerView playerView;

    private String movieUrl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.movie_player);
        movieUrl = getIntent().getStringExtra("movie_url");
        playerView = findViewById(R.id.movie_player_view);
        playerView.setShowSubtitleButton(true);




    }


    @Override
    public void onStart() {
        super.onStart();
        if (movieUrl != null) {
            initializePlayer(movieUrl);
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        stopPlayer();
    }

    private void initializePlayer(String url) {
        // Release the player if it already exists
        releasePlayer();

        // Create an ExoPlayer instance.
        player=new ExoPlayer.Builder(getApplicationContext()).build();

        playerView.setPlayer(player);
        playerView.setUseController(true);


        // Set the player's listener.
        player.addListener(new Player.Listener() {
            @Override
            public void onPlaybackStateChanged(int playbackState) {
                if (playbackState == Player.STATE_ENDED) {
                    // Exit the player when the movie ends.
                    stopPlayer();
                    finish();
                }
            }
        });

        // Prepare and play the media.
        MediaItem mediaItem = MediaItem.fromUri(url);
        player.setMediaItem(mediaItem);
        player.prepare();
        player.play();
    }


    public void releasePlayer() {
        if (player != null) {
            player.release();
            player = null;
        }
    }


    public void stopPlayer() {
// Check if the player is already stopped.
        if (player == null || !player.isPlaying()) {
            return;
        }

        player.stop();
        releasePlayer();

    }

    @Override
    public void onBackPressed() {
        stopPlayer();
        super.onBackPressed();
    }
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:layoutMode="clipBounds">


    <com.google.android.exoplayer2.ui.StyledPlayerControlView
        android:id="@+id/movie_player_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:show_next_button="false"
        app:show_subtitle_button="true" />

</androidx.constraintlayout.widget.ConstraintLayout>

Image from TV

when i run from the emulator it displays correctly.Image from the emulator

0

There are 0 best solutions below