Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only audio is played without video #5683

Closed
mansurrrr opened this issue Mar 26, 2019 · 2 comments
Closed

Only audio is played without video #5683

mansurrrr opened this issue Mar 26, 2019 · 2 comments
Assignees
Labels

Comments

@mansurrrr
Copy link

mansurrrr commented Mar 26, 2019

Currently I'm using SimpleExoPlayer for VOD playback.

When RenderersFactory.createRenderers is used for
SimpleExoPlayer.newSimpleInstance(Context context, RendererFactory factory, Trackselector trackselector)
, only the audio is output without the video being displayed.

Use DefaultRenderersFactory(Context context) works normally.

[REQUIRED] Question

To use createMessage for change surface, I need to use A and specify MediaCodecVideoRenderer as a variable. I wonder what the difference is and how to solve it.

Or Is there a way to get MediaCodecVideoRenderer from DefailtRenderersFactory (When using SimpleExoPlayer.setVideoSurface(surface), surface not change immediately.)

Please check code below

[Only audio is played without video]

TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
        DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

        RenderersFactory factory = (Handler eventHandler, VideoRendererEventListener videoRendererEventListener, AudioRendererEventListener audioRendererEventListener, TextOutput textRendererOutput, MetadataOutput metadataRendererOutput, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) -> {
            mVideoRenderer = new MediaCodecVideoRenderer(mContext, MediaCodecSelector.DEFAULT, 5000);
            mAudioRenderer = new MediaCodecAudioRenderer(mContext, MediaCodecSelector.DEFAULT);
            return new Renderer[]{mVideoRenderer, mAudioRenderer};
        };
        
        mBinding.commonPlayerView.requestFocus();
        mPlayer = ExoPlayerFactory.newSimpleInstance(mContext, factory, trackSelector);

        mBinding.commonPlayerView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.black));
        mBinding.commonPlayerView.setUseController(false);
        mBinding.commonPlayerView.setPlayer(mPlayer);

[Works both video and audio]

TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
        DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

        mBinding.commonPlayerView.requestFocus();
        mPlayer = ExoPlayerFactory.newSimpleInstance(mContext, new DefaultRenderersFactory(mContext), trackSelector);

        mBinding.commonPlayerView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.black));
        mBinding.commonPlayerView.setUseController(false);
        mBinding.commonPlayerView.setPlayer(mPlayer);

@marcbaechinger
Copy link
Contributor

I think I currently don't understand the reason why you want to use a custom RenderersFactory. Can you elaborate on what you try to achieve when you are saying: "use createMessage for change surface"?

The code snippet you are providing shows that you are using SimpleExoPlayer:

 mPlayer = ExoPlayerFactory.newSimpleInstance

So when it comes to switching surfaces I would recommend to use the API of SimpleExoPlayer which allows you to set the surface:

void setVideoSurfaceHolder(SurfaceHolder surfaceHolder);

If you are using this method you would not need to use createMessage which does not seem to be the preferred way for an app to switch the surface.

@ojw28
Copy link
Contributor

ojw28 commented Apr 5, 2019

I think the original poster is trying to find a non-standard way to swap the surface due to:

(When using SimpleExoPlayer.setVideoSurface(surface), surface not change immediately.)

Internally that method is sending a message to swap the surface, just as you're attempting to do with your custom solution. In order words, your custom solution wont be any better, so you may as well stop trying to make that work.

Being able to instantaneously swap the surface isn't possible on some older devices due to underlying platform limitations, as discussed in some depth here. You should find it works much better on most newer devices. There is also finally a comprehensive solution to this problem coming in Android Q.

@ojw28 ojw28 closed this as completed Apr 5, 2019
@google google locked and limited conversation to collaborators Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants