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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With