J'ai un objet Article que je veux afficher dans mon activité. Un article peut avoir: -Text (s): 1 au moins ou plusieurs -Image (s): 0 ou plusieurs -Vidéo (s): 0 ou plusieursAfficher plusieurs vidéos YouTube dans une activité
Chaque élément peut se situer dans l'article de exemple: -Texte/image/texte/vidéo -Vidéo/image/Vidéo/texte - etc ...
Après l'analyse de mon article, j'ajoute le programme contenu j'ai besoin: TextView, ImageView ou VideoView (youtube ou jwplayer). En fait, il travaille pour l'image et le texte, mais je ne sais pas comment je peux ajouter plusieurs vidéos youtube dans une même activité:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.post);
linearLayout = (LinearLayout) findViewById(R.id.llayout_article);
// Get article to display it
Intent intent = getIntent();
Article article = intent.getParcelableExtra("articleDetails");
//add ImageView & TextView
for (View view : article.getContentSplitInViews(this)) {
this.linearLayout.addView(view);
}
YouTubePlayerSupportFragment frag =
(YouTubePlayerSupportFragment) getSupportFragmentManager().findFragmentById(R.id.youtube_fragment);
src="g2mmUzNSeDM";
frag.initialize(apiKey, this);
YouTubePlayerSupportFragment frag2 =
(YouTubePlayerSupportFragment) getSupportFragmentManager().findFragmentById(R.id.youtube_fragment2);
src = "nCgQDjiotG0";
frag2.initialize(apiKey, this);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {
if (!wasRestored) {
youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
youTubePlayer.loadVideo(src);
youTubePlayer.play();
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
// YouTube error
String errorMessage = youTubeInitializationResult.toString();
Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_LONG).show();
Log.d("errorMessage:", errorMessage);
}
Mon xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/scrollViewId"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="@+id/llayout_article"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:id="@+id/youtube_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:id="@+id/youtube_fragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
Plus tard, je veux ajouter programmaticaly l'étiquette de fragment dans mon XML pour chaque vidéo trouvée dans l'article d'article.
En fait, il y a 2 joueurs dans mon activité, mais un seul joue la vidéo, et l'action dans chaque joueur (lecture/pause/plein écran) fera la même chose chez les 2 joueurs.
https://androidtutorialmagic.wordpress.com/my-mini-project/multiple-youtube-video-in-recyclerviewlistview-in-android/ –
Bon tutoriel, mais je n'ai pas vraiment voulez utiliser youtubeStandAlonePlayer. Est-il possible d'afficher plusieurs vidéos, puis de jouer la bonne en cliquant sur "play button"? – gamerounet