'Exoplayer doesnt play any video

Have a problem getting Exoplayer to work. I managed to load the video from a url. But it only plays the audio. So i am doing something wrong.

    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    LoadControl loadControl = new DefaultLoadControl();
    SimpleExoPlayer exoPlayer = ExoPlayerFactory.newSimpleInstance(simpleExoPlayerView.getContext(), trackSelector, loadControl);

    Uri mp4VideoUri = Uri.parse(videoUri);
    DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("ExoPlayerDemo");
    ExtractorsFactory extractor = new DefaultExtractorsFactory();

    MediaSource videoSource = new ExtractorMediaSource(mp4VideoUri, dataSourceFactory, extractor, null, null);
    exoPlayer.prepare(videoSource);

    exoPlayer.setPlayWhenReady(true);

This is how i where able to only play the audio. Not sure what i should change.



Solution 1:[1]

Looks like you miss to bind player to player view

Attaching player to view

The ExoPlayer library provides a SimpleExoPlayerView, which encapsulates a PlaybackControlView and a Surface onto which video is rendered. A SimpleExoPlayerView can be included in your application’s layout xml. Binding the player to the view is as simple as:

// Bind the player to the view.
simpleExoPlayerView.setPlayer(player);

If you require fine-grained control over the player controls and the Surface onto which video is rendered, you can set the player’s target SurfaceView, TextureView, SurfaceHolder or Surface directly using SimpleExoPlayer’s setVideoSurfaceView, setVideoTextureView, setVideoSurfaceHolder and setVideoSurface methods respectively. You can use PlaybackControlView as a standalone component, or implement your own playback controls that interact directly with the player. setTextOutput and setId3Output can be used to receive caption and ID3 metadata output during playback.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community