Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exoplayer not playing video only audio plays

ExoPlayer is not showing the video. I can listen the audio but video is not playing. I am using the Exoplayer in the Recyclerview.I only can see the black screen and listen to audio.I am not able to track the problem. I am playing the HLS video in the ExoPlayer.

like image 659
Shikha Ratra Avatar asked Nov 09 '22 11:11

Shikha Ratra


2 Answers

I was also getting same issue few days back, now posting it here so that it can make someone's life easy since this problem appears very often when we use Exoplayer with RecyclerView.

Cause of the issue (in my case):

PlayerView was getting changed every time I came on the screen (due to the presence of RecyclerView)

I handled it by setting the player each time on the PlayerView object inside showLivePlayer() method which is called each time recycler view enabled screen opens to play the video.

    public void showLivePlayer(PlayerView playerView, String videoURL, String tokenURL, ProgressBar progressBar){

        mPlayerView = playerView;
        if(player != null)
            mPlayerView.setPlayer(player);  //THIS IS THE FIX

        mProgressBar = progressBar;
        //register event bus
        if (!EventBus.getDefault().isRegistered(this))
            EventBus.getDefault().register(this);

        shouldAutoPlay = true;
        bandwidthMeter = new DefaultBandwidthMeter();
        mediaDataSourceFactory = new DefaultDataSourceFactory(mContext,
                Util.getUserAgent(mContext, mContext.getString(R.string.app_name)), bandwidthMeter);
        window = new Timeline.Window();
        getLiveVideoToken(tokenURL, videoURL);
}
like image 86
Soft Kaka Avatar answered Nov 14 '22 20:11

Soft Kaka


my bad was I was using PlayerControlView instead of PlayerView

like image 28
Boy Avatar answered Nov 14 '22 20:11

Boy