Good morning, I'm having several problems playing a video with the exoplayer. More precisely, I'm trying to create an Android app to be able to deploy it on Pepper's tablet which interfaces with a website that allows you to create and upload social stories with images, videos and audio. We checked the site to see if there were any problems with php, but nothing. Therefore, while I was debugging the app I noticed that when we start the social story with the video present inside, the player loads correctly but after a second the player crashes, causing the audio to play after it returns to the main screen, and after that ends the audio of the video completely crashes the entire app. We believe it is a race condition problem but we are not very sure of this as the exception passed to us by debug is of type RuntimeException. We look forward to your advice and thank you in advance! I attach the handler script below
private void getParagraph() {
Log.d("prova", "valore array paragrafi: " +story.size());
Log.d("prova", "valore array immagini: " +imageList.size());
Log.d("prova", "prova bitmap: " + imageList.get(index));
if (imageList.get(index) != null) {
imageView.setBackgroundColor(255);
imageView.setImageBitmap(imageList.get(index));
} else if (!videoName.get(index).isEmpty()) { //SE IL NOMEVIDEO NELLA COLONNA DEL DATABASE E' PRESENTE
//SE NON SOSTITUISCO GLI SPAZI CON I CARATTERI %20, IL VIDEO NON VIENE VISUALIZZATO
String storyTableNoSpace = PepperStory.storyTitle;
storyTableNoSpace = storyTableNoSpace.replaceAll(" ", "%20");
Log.d("prova video", "prova stringa storyTableNoSpace: " + storyTableNoSpace);
String string = "https://pepper4socialstory.altervista.org/get_video2.php?table=" + storyTableNoSpace + "&id=" + index;
Log.d("prova video", "prova stringa connessione: " + string);
//String string = "https://pepper4storytelling.altervista.org/get_video2.php?table=" + PepperStory.storyTitle + "&id=" + index;
//Log.d("prova video", "prova stringa connessione: " + string);
imageView.setVisibility(imageView.INVISIBLE);
simpleVideoExoPlayer = new SimpleExoPlayer.Builder(this).build(); //null
videoView.setPlayer(simpleVideoExoPlayer);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "app"));
MediaSource dataSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(string));
videoView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
videoView.setControllerHideOnTouch(true);
simpleVideoExoPlayer.prepare(dataSource);
simpleVideoExoPlayer.setPlayWhenReady(true);
//FIXME
simpleVideoExoPlayer.addListener(new Player.EventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if(playbackState == Player.STATE_ENDED) {
Log.d("prova video", "IS PLAYING: " +simpleVideoExoPlayer.isPlaying());
Log.d("prova video", "SONO NEL LISTENER STATO FINITO");
//TODO: aggiunta adesso
if(simpleAudioExoPlayer == null || simpleAudioExoPlayer.isPlaying() == false) {
Log.d("flusso", "sono nel getParagraph dell'if dell'end simpleVideoPlayer");
nextParagraph.setVisibility(nextParagraph.VISIBLE);
imageView.setBackgroundColor(255);
videoView.setLayoutParams(new FrameLayout.LayoutParams(1, 1));
index = index +1;
imageView.setVisibility(imageView.VISIBLE);
nextParagraph.setVisibility(nextParagraph.INVISIBLE);
getParagraph();
}
}
}
});
} else {
imageView.setImageBitmap(null);
imageView.setBackgroundColor(Color.parseColor(color.get(index)));
}
if (!audioName.get(index).isEmpty()) { //SE IL NOMEAUDIO NELLA COLONNA DEL DATABASE E' PRESENTE
//SE NON SOSTITUISCO GLI SPAZI CON I CARATTERI %20, L'AUDIO NON VIENE RIPRODOTTO
String storyTableNoSpace = PepperStory.storyTitle;
storyTableNoSpace = storyTableNoSpace.replaceAll(" ", "%20");
Log.d("prova video", "prova stringa storyTableNoSpace: " + storyTableNoSpace);
String string = "https://pepper4socialstory.altervista.org/get_audio.php?table=" + storyTableNoSpace + "&id=" + index;
Log.d("prova video", "prova stringa connessione: " + string);
//String string = "https://pepper4storytelling.altervista.org/get_audio.php?table=" + PepperStory.storyTitle + "&id=" + index;
//Log.d("prova audio", "prova stringa connessione: " + string);
simpleAudioExoPlayer = new SimpleExoPlayer.Builder(this).build();
audioView.setPlayer(simpleAudioExoPlayer);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "app"));
MediaSource dataSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(string));
//audioView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
audioView.setControllerHideOnTouch(true);
simpleAudioExoPlayer.prepare(dataSource);
simpleAudioExoPlayer.setPlayWhenReady(true);
simpleVideoExoPlayer.addListener(new Player.EventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == Player.STATE_ENDED) {
Log.d("prova video", "IS PLAYING: " + simpleVideoExoPlayer.isPlaying());
Log.d("prova video", "SONO NEL LISTENER STATO FINITO");
// TODO: aggiunta adesso
if (simpleAudioExoPlayer == null || !simpleAudioExoPlayer.isPlaying()) {
Log.d("flusso", "sono nel getParagraph dell'if dell'end simpleVideoPlayer");
runOnUiThread(new Runnable() {
@Override
public void run() {
nextParagraph.setVisibility(View.VISIBLE);
imageView.setBackgroundColor(Color.WHITE); // Imposta il colore di sfondo bianco
videoView.setLayoutParams(new FrameLayout.LayoutParams(1, 1));
index = index + 1;
imageView.setVisibility(View.VISIBLE);
nextParagraph.setVisibility(View.INVISIBLE);
getParagraph();
}
});
}
}
}
});
}
startTalk();
}
Assuming the race condition problem, we tried to use Syncronize() when it increments the index, but nothing