Skip to content
Advertisement

How to fix error YouTubeInitializationResult.SERVICE_INVALID

I try use Youtube API in my Android App, my app looke like this:

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  ytpv = (YouTubePlayerView) findViewById(R.id.youtubeplayer);
  ytpv.initialize("this is my key", this);

  et = (EditText) findViewById(R.id.eturl);
  et.setOnEditorActionListener(this);
}

@Override
public void onInitializationFailure(Provider arg0,YouTubeInitializationResult arg1) {
 if(arg1 == YouTubeInitializationResult.DEVELOPER_KEY_INVALID)
     Toast.makeText(this, "Initialization Fail- key invalid", Toast.LENGTH_LONG).show();
 else if(arg1 == YouTubeInitializationResult.SERVICE_INVALID)
     Toast.makeText(this, "Initialization Fail- Service invalid", Toast.LENGTH_LONG).show();
 else if(arg1 == YouTubeInitializationResult.INVALID_APPLICATION_SIGNATURE)
     Toast.makeText(this, "Initialization Fail- invalid application", Toast.LENGTH_LONG).show();
}

@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player,boolean wasrestored) {
ytp = player;
Toast.makeText(this, "Initialization  Success", Toast.LENGTH_LONG).show();
}

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
 if(actionId == EditorInfo.IME_ACTION_GO ){
   if(ytp !=null){
      ytp.loadVideo(et.getText().toString());
   }
 }
 return false;
}

But when i install on my real device, I get a error : Initialization Fail- Service invalid I have no idea to fix this error. Let me hear your idea, thank you 🙂

Advertisement

Answer

The Android YouTube API docs at: https://developers.google.com/youtube/android/player/ includes this note:

Note: Users need to run version 4.2.16 of the mobile YouTube app (or higher) to use the API.

I was getting a similar error until I upgraded the version of the YouTube app on my testing device.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement