Reputation: 351
I am try to play video using youtube video API
When I put static ID means declare ID in file at that time code is working.
But when I try to fetch ID from getIntent() I also got ID but video not play.
I got There was problem with network.
Below is my code. Its working in this condition.
public String VIDEO = "QqnBjKnwCwE";
youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(DEVELOPER_KEY, Videosshow.this);
@Override
public void onInitializationFailure(Provider provider,
YouTubeInitializationResult error) {
Toast.makeText(this, "Oh no! " + error.toString(), Toast.LENGTH_LONG)
.show();
}
@Override
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
player.loadVideo(String.valueOf( VIDEO));
}
Now When I used
Bundle data = getIntent().getExtras();
VIDEO=data.getString("videourl");
youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(DEVELOPER_KEY, Videosshow.this);
not working I got 400 Network problem error
Upvotes: 3
Views: 4610
Reputation: 1861
I figured out that the id I was sending was incorrect, it had an extra = (say =hdeFZ6nt9tc)which was not to be sent. The problem occurred as I was extracting it from the youtube's actual URL(say https://www.youtube.com/watch?v=hdeFZ6nt9tc). I hope even you too might have been sending the wrong id. Double check it again even if you are pretty sure. What I think is youtube must send a 404(which generally refers to "Page Not Found" on the web) for such requests.
Upvotes: 1
Reputation:
I had same the problem but retrieving video id from url solved my problem.
String video_id=jsonObject.getString("id");
Thank You ritesh.
Upvotes: 0
Reputation: 627
Check your id .I think there is space in id or youtube url either start or end .I have similar problem and solved by this .You should also try .It may be help for if you have setup all properly .
Upvotes: 1