Relevant part of the activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub_item);
loadTopico();
}
private void loadTopico() {
YouTubePlayerFragment mainVideo = (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.main_video);
mainVideo.initialize(Config.YOUTUBE_API, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVide(getResources().getString(R.string.principal_funcoes));
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});
YouTubePlayerFragment secondVideo = (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.secondVideo);
secondVideo .initialize(Config.YOUTUBE_API, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVideo(getResources().getString(R.string.secundario));
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});
The intended result was to have the two fragments have a video each, and also be independent from each other.
The problem I'm facing is that the fragments don't have a video each, nor they're independent. Both load together, and everything done in one of the fragments (pressing play or pause) completely changes what happens in the other fragment.
The planned feature for this activity is show a feed of videos for the user to press play and watch each video individually, but as stated, that's not possible due to the fragments completely destroying each other.
What can I possibly do for the problem to be solved?
//EDIT R.layout.activity_sub_item:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="kerooker.me.matematicando.SubItem"
android:id="@+id/mainRelative">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.google.android.youtube.player.YouTubePlayerFragment"
android:layout_below="@+id/textoAssista"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:id="@+id/main_video" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/texto_assista"
android:id="@+id/textoAssista"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:layout_marginLeft="10dp"
android:textSize="18sp" />
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.google.android.youtube.player.YouTubePlayerFragment"
android:layout_below="@+id/main_video"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:id="@+id/secondary_video" />
</RelativeLayout>