I'd like to know if there is a way to use both YouTubeBaseActivity and having benefits of AppCompatActvity.
The main idea is to play a youtube video inside a dialogFragment.
Any idea?
I've finally find how to play embeded youtube video in a dialog.
Just have to create a custom layout for your dialog and inflate it in a class that extends DialogsFragment.
In this custom layout you add a framelayout which will become a youtubefragment container. Don't forget to make your Dialog implements YouTubePlayer interfaces and it's almost done.
Final trick use getChildFragmentManager instead of supportFragmentManager for the transaction that add youtube player fragment in your container.
Here is some code that for your dialog class:
public class AddMarkerFragment extends DialogFragment implements YouTubePlayer.OnInitializedListener{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
Log.d("ADDMARKERLIFECYCLE","ONCREATE");
final View view = inflater.inflate(R.layout.fragment_add_marker, container, false);
prepareYoutubePlayer(view);
}
private void prepareYoutubePlayer(View view) {
youtubePlayerFragment = (YouTubePlayerSupportFragment)
getActivity().getSupportFragmentManager().findFragmentById(R.id.youtube_fragment);
if (youtubePlayerFragment == null) {
youtubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
getChildFragmentManager().beginTransaction().add(R.id.youtube_fragment, youtubePlayerFragment).commit();
}
youtubePlayerFragment.initialize(YoutubeConnector.KEY, this);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {
if (!wasRestored) {
youTubePlayer.loadVideo(footage.getYoutubeID());
this.youtubePlayer=youTubePlayer;
/* youTubePlayer.setShowFullscreenButton(false);
youTubePlayer.*/
youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.e(CreateExperienceActivity.class.getSimpleName(), "Ruh Roh!");
}
Keeping the youtube player in reference can be use full to implement your own controll (play/pause etc etc etc)
Hope it will help some body.
Regards,