'Android Exoplayer only playing audio without video

I'm accessing an mp4 file on the web - it runs just fine in the browser but for some reason I can only seem to get the audio portion to work in my app. Any help would be appreciated.

Relevant Gradle:

android {
    compileSdkVersion 28
        minSdkVersion 17
        targetSdkVersion 28

    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation "com.android.support:support-compat:28.0.0"
    implementation "com.android.support:support-media-compat:28.0.0"
    implementation "com.google.android.exoplayer:exoplayer-core:2.7.2"
    implementation "com.google.android.exoplayer:exoplayer-ui:2.7.2"
}

Layout View:

<com.google.android.exoplayer2.ui.PlayerView
    android:id="@+id/playerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="0dp"
    android:layout_marginRight="0dp"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginBottom="0dp"
    android:layout_marginLeft="0dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/horizontalHalf"
     />

Relevant code within Fragment:

private SimpleExoPlayer mExoPlayer;
private static MediaSessionCompat mMediaSession;
private PlaybackStateCompat.Builder mStateBuilder;



BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
                new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
                new DefaultTrackSelector(videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(mParentActivity);

mExoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl);
mPlayerView.setPlayer(mExoPlayer);

mExoPlayer.addListener(this);

DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(mParentActivity, "APP_NAME");
DefaultExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();

MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).setExtractorsFactory(extractorsFactory).createMediaSource(mediaUri);

mExoPlayer.prepare(mediaSource);
mExoPlayer.setPlayWhenReady(true);


Solution 1:[1]

Oh boy is this a weird one... so it turns out that the issue is that setting the background theme for the app causes the exoplayer display to be hidden...

So even just having this defined was enough. If I removed the background from here, everything works. I still don't know how to both show this video and have a background set, though...

> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
>     <!-- Customize your theme here. -->
>     <item name="android:background">@color/colorPrimary</item> </style>

I hope that having this here will help someone else in the future avoid this issue.

Solution 2:[2]

In my case, hardware-accelerated was set to false in the manifest.

android:hardwareAccelerated="true" is needed for texture view in exoplayer to work.

Solution 3:[3]

Would you mind trying HlsMediaSource? This normally works for me

val bandwidthMeter = DefaultBandwidthMeter()
val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory(bandwidthMeter)
val trackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
player = ExoPlayerFactory.newSimpleInstance(context, trackSelector)

val dataSourceFactory = OkHttpDataSourceFactory(
          OkHttpClient(),
          Util.getUserAgent(context, context.getString(R.string.app_name)),
          bandwidthMeter
)
val videoSource = HlsMediaSource.Factory(dataSourceFactory)
          .createMediaSource(Uri.parse(url))

player?.prepare(videoSource)

Also, adding this to your gradle's dependencies

implementation "com.google.android.exoplayer:extension-okhttp:2.7.2"

Solution 4:[4]

Please check your code , PlayerView setPlayer more than one may lead to the problem ...

Solution 5:[5]

I've had the same problem. I forgot to add the code below, it was fixed when I added it.

playerView.setPlayer(player);

Solution 6:[6]

My case was weird. I tried to avoid deprecated methods and i was using:

new ExoPlayer.Builder(this, new MediaCodecVideoRenderer(this, MediaCodecSelector.DEFAULT), new MediaCodecAudioRenderer(this, MediaCodecSelector.DEFAULT)).build();

I have changed it to:

new SimpleExoPlayer.Builder(this).build();

This solved my problem.

Solution 7:[7]

in my case I had this style

 <style name="Theme.EnglishApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <item name="colorPrimary">@color/red700</item>
    <item name="colorPrimaryDark">@color/red900</item>
    <item name="colorAccent">@color/red700</item>
    <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
    <!-- the problem is this item -->
    <item name="android:background">@color/black</item>
    <!-- the problem is this item -->
</style>

and when I removed this item

<item name="android:background">@color/black</item>

my problem fixed

Solution 8:[8]

The issue was that the theme used in the manifest had background defined as

<item name="android:background">@color/white</item>

which was making the video kind of invisible and instead showing a white screen. Removing this line solved the problem

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 notnot
Solution 2 a0x2
Solution 3
Solution 4 BertKing
Solution 5 Emircan Pekyürek
Solution 6 Numan Karaaslan
Solution 7 Mahdi Zareei
Solution 8 Sonu Sourav