Код: Выделить всё
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();
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... oexoplayer