Please check whether "YouTube" application is install on your device? If yes then just update it.And most of the time you tube application not working properly on emulator..
Get a You Tube Player using Google Console key
-
15-10-2022 - |
Pregunta
I am trying to add a You Tube video to my project.so,I got a key from Google Console.Then I got a error occurred while initializing the You Tube player.
Coding:
public class YoutubePlayActivity extends YouTubeFailureRecoveryActivity{
public static final String DEVELOPER_KEY = "AIzaSyC-_QFOSG2hHUhCHtahzloDr7CR-Swt6lM";
private String videoId;
private YouTubePlayerView youTubeView;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.youtube_play);
Bundle bundle= getIntent().getExtras();
videoId= bundle.getString("videoid");
FrameLayout frameLayout=(FrameLayout) findViewById(R.id.youtube_view);
youTubeView = new YouTubePlayerView(this);
frameLayout.addView(youTubeView);
youTubeView.initialize(DEVELOPER_KEY, this);
((TextView) findViewById(R.id.header_title)).setText(bundle.getString("title"));
findViewById(R.id.blog_back).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
if (!wasRestored) {
try {
if(videoId!=null){
//2GPfZYwYZoQ
player.cueVideo(videoId);
}else{
Toast.makeText(getApplicationContext(), "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
}
}
}
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return youTubeView;
}
}
Output:
If I click the Get You Tube App.Then the Output seems like these:
Logcat Error:
Finally Logcat Error Occurred:
Then I try to change the key from Google Console.Again these kind of errors occurred.I have to get a You Tube App with the help of coding.That's why I am using a Google Console key.Anybody know how to solve these.Waiting for your reply.Thank you.
Solución
Otros consejos
Change:
player.cueVideo(videoId);
to:
player.loadVideo(videoId);
'OR'
First check that Video id is correct or not?
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow