I have a SimpleExoPlayer item in my TV application, when i run the activity the player works normally, the player has UDP mediaSource and all is fine when i go to another activity and come back to the current activity, the SimpleExoPlayer player play just audio without video this is my item
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/player_view"
android:layout_width="400dp"
android:layout_height="310dp"
app:shutter_background_color="@android:color/transparent"
app:layout_constraintStart_toEndOf="@+id/tv_frame_content"
android:layout_alignEnd="@+id/tv_frame_content"
app:layout_constraintTop_toTopOf="@+id/tv_frame_content"
app:layout_constraintBottom_toBottomOf="@+id/tv_frame_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="50dp"
app:keep_content_on_player_reset="true"
android:layout_marginEnd="50dp"
app:use_controller="false" />
this is how i play in onResume of my fragment
public void initPlayer(String url, PlayerView playerView, String activity) {
if (url.isEmpty())
Toast.makeText(getContext(), "Please enter a url", Toast.LENGTH_SHORT).show();
else {
playerView.setShutterBackgroundColor(Color.TRANSPARENT);
// playerView.setPlayer(null);
//if (isPlaying2) {
// stopPlayer2();
// } else {
App.appendLog("PLAYING FROM :" + activity + "---" + url);
Uri videoUri = Uri.parse(url);
Toast.makeText(getContext(), url, Toast.LENGTH_SHORT).show();
//Create a default TrackSelector
DefaultTrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory());
trackSelector.setParameters(
trackSelector.getParameters().buildUpon().setMaxVideoSizeSd()
.setPreferredTextLanguage("en")
.setPreferredAudioLanguage("en").build());
//Create the player
player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector);
// set player in playerView
playerView.setPlayer(player);
playerView.requestFocus();
//Create default UDP Datasource
DataSource.Factory factory = () -> new UdpDataSource(5000, 100000);
// ExtractorsFactory tsExtractorFactory = () -> new TsExtractor[]{new TsExtractor(MODE_SINGLE_PMT,
// new TimestampAdjuster(0), new DefaultTsPayloadReaderFactory())};
MediaSource mediaSource = new ProgressiveMediaSource.Factory(factory)
.createMediaSource(videoUri);
// new ExtractorMediaSource(videoUri, factory, tsExtractorFactory, null, null);
player.prepare(mediaSource);
player.addListener(new Player.EventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
Player.EventListener.super.onPlayerStateChanged(playWhenReady, playbackState);
if (playWhenReady && playbackState == Player.STATE_READY) {
// isPlaying2 = true;
// media actually playing
} else if (playWhenReady) {
// might be idle (plays after prepare()),
// buffering (plays when data available)
// or ended (plays when seek away from end)
} else {
// player paused in any state
}
}
@Override
public void onPlayerError(ExoPlaybackException error) {
Player.EventListener.super.onPlayerError(error);
App.appendLog("ERROR in player Main fragment: " + error + "");
Toast.makeText(getContext(), error + "", Toast.LENGTH_LONG).show();
//isPlaying2 = false;
}
@Override
public void onSeekProcessed() {
Player.EventListener.super.onSeekProcessed();
}
});
// start play automatically when player is ready.
player.setPlayWhenReady(true);
playerView.setShutterBackgroundColor(Color.TRANSPARENT);
player.addAnalyticsListener(new EventLogger(trackSelector));
}
//}
}
function stop player
public void stopPlayer() {
if (player != null) {
player.stop();
App.appendLog("STOPPED: ");
}
}
these is something wrong !! cannot find any solution