I know this might have been asked before, but this is a special case I am involved into..
IMPORTANT I need to do this inside a separate class, not an activity. Actually my class extends a BaseViewPagerAdapter wrote by someone else..
The idea is that, I can't use YoutubePlayerView because I can not extend YoutubeBaseActivity.
I also tried using YoutubePlayerSupportFragment, same not working because I can't get the refernce for the from my XML file...
I did try something like this
public class YTVideoFragment extends YouTubePlayerSupportFragment {
private final static String TAG = "YoutubeVideoFragment";
private static final String DEV_KEY = "key";
private static String id;
private YouTubePlayer mPlayer;
public static YTVideoFragment newInstance(String url){
YTVideoFragment videoFragment = new YTVideoFragment();
Bundle bundle = new Bundle();
bundle.putString("uri", url);
videoFragment.setArguments(bundle);
videoFragment.init(0);
Log.i(TAG, "new Instance FINAL ");
return videoFragment;
}
public void init(final int time) {
initialize(DEV_KEY, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
mPlayer = youTubePlayer;
Log.i(TAG, "-=onInitializationSuccess=-");
mPlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
id = getArguments().getString("url");
if (!b){
mPlayer.loadVideo(id, time);
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.i(TAG, "-=onInitializationFailure=-");
Log.e(TAG, youTubeInitializationResult.toString());
}
});
}
}
And I made an instance of this into the class that extends BaseViewPageAdapter and tried to do
YouTubePlayerSupportFragment youtube = YouTubePlayerSupportFragment.newInstance();
youtube.getFragmentManager().beginTransaction().replace(R.id.youtubeplayerfragment,youtube);
But there I get an error that replace function is applied on a null object reference ..
If you have any suggestion, or idea how I could make it work on this particular case I would be grateful