Im trying to use the Youtube Player Support Fragment in a fragment but the app always crash (NullPointerException) and I have not been able to find any similar post to fix i
CzarMatt nailed it. Just to add to his answer though, don't forget you need to call the init()
method. To do so follow CzarMatt's code and add one line:
public static PlayerYouTubeFrag newInstance(String url) {
PlayerYouTubeFrag playerYouTubeFrag = new PlayerYouTubeFrag();
Bundle bundle = new Bundle();
bundle.putString("url", url);
playerYouTubeFrag.setArguments(bundle);
playerYouTubeFrag.init(); //This line right here
return playerYouTubeFrag;
}
Also, since I'm sure people will run into the same issue I did, even though CzarMatt mentioned it above, just to reiterate, when you pass in a URL for the video, you are NOT passing in the youtube URL
That is, with: "youtube.com/watch?v=z7PYqhABiSo&feature=youtu.be"
You are passing in only the video ID
I.e. use: "z7PYqhABiSo"
Since it is Google's own documentation, it knows how to play it just fine with the id.