Exoplayer: Exoplayer black screen onResume()

Created on 8 Oct 2015  路  4Comments  路  Source: google/ExoPlayer

Hello,
I am facing the following issue
While playing any video, if I pressed home button and come back to app (player screen). its showing the black screen. then i pressed play video , the video start playing. How to fixed the issue of black screen and show the video frame at which video is paused?

Most helpful comment

Get the same problem,then I debug into the code,this is caused by video tracker is release
so I reinstance tracker in onSurfaceViewCreated锛宲roblem resolved

    public void surfaceCreated(SurfaceHolder holder) {

        surfaceHolder = holder;

        if (exoPlayer == null) {
            exoPlayer = ExoPlayer.Factory.newInstance(2);
            playerControl = new PlayerControl(exoPlayer);
            allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
            dataSource = new DefaultUriDataSource(getContext(), "this is agent");
            exoPlayer.addListener(this);
        }

        if (videoRenderer != null) {
            assemblyTrackRender(playlist.get(currentPlayingIndex));
            exoPlayer.prepare(videoRenderer, audioRenderer);
        }
    }

    private void assemblyTrackRender(TrainingResource resource) {
        sampleSource = new ExtractorSampleSource(Uri.fromFile(new File(resource.getLocation())), dataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);
        videoRenderer = new MediaCodecVideoTrackRenderer(getContext(), sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
        audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

        exoPlayer.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surfaceHolder.getSurface());
    }

All 4 comments

If I change this line to use false rather than true in the demo app, then the demo app will default to the paused state rather than the player state. If I then press home and come back to the app, I see the frame restored correctly after a short period of time which is needed to re-buffer the data.

So this sounds like an issue with your application rather than with the library. Perhaps you're not instantiating/preparing the player properly in onResume.

Note - One possible cause would be if you are using the deprecated FrameworkSampleSource. If you are then that's a platform limitation, and if at all possible you should use ExtractorSampleSource instead.

call exoplayer.prepare() in onSurfaceTextureAvailable

Get the same problem,then I debug into the code,this is caused by video tracker is release
so I reinstance tracker in onSurfaceViewCreated锛宲roblem resolved

    public void surfaceCreated(SurfaceHolder holder) {

        surfaceHolder = holder;

        if (exoPlayer == null) {
            exoPlayer = ExoPlayer.Factory.newInstance(2);
            playerControl = new PlayerControl(exoPlayer);
            allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
            dataSource = new DefaultUriDataSource(getContext(), "this is agent");
            exoPlayer.addListener(this);
        }

        if (videoRenderer != null) {
            assemblyTrackRender(playlist.get(currentPlayingIndex));
            exoPlayer.prepare(videoRenderer, audioRenderer);
        }
    }

    private void assemblyTrackRender(TrainingResource resource) {
        sampleSource = new ExtractorSampleSource(Uri.fromFile(new File(resource.getLocation())), dataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);
        videoRenderer = new MediaCodecVideoTrackRenderer(getContext(), sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
        audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

        exoPlayer.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surfaceHolder.getSurface());
    }
Was this page helpful?
0 / 5 - 0 ratings