Youtube API "An error occurred while initializing the YouTube player."

24,891

Solution 1

I was having this problem. Then I just added

<uses-permission android:name="android.permission.INTERNET"/> into the AndroidManifest.xml in the <manifest> tag. The app worked fine after that.

Solution 2

I've fixed this problem by doing steps below:

  • Clean project then Rebuild Project
  • Run the app in a device which has an Youtube app with a version higher than 4.2.16.

Solution 3

Just update your youtube app to the latest version in your phone and it will work perfect

Solution 4

maybe, it seems to developer key problem. sample DEVELOPER_KEY key that located in DeveloperKey.java will be not work. first, register a new developer key. (https://code.google.com/apis/console) then, replace this with a valid key.

Solution 5

right click on project go to properties->java built in path->libraries->Add library and add your jar file there and then it's working

if you want to use youtube video in your application your device must have to contain an application of youtube otherwise it will not work

Share:
24,891
Admin
Author by

Admin

Updated on February 14, 2022

Comments

  • Admin
    Admin over 2 years

    I'm using Youtube API to have simple playerView on my application. I did what the API said to do but I keep getting "application is stopped" message. I don't really know the exact english phrase since I'm using a Korean Phone. Hope that's the right phrase in English.

    I put Youtubeandroidplayerapi.jar in libs and built the path and have the unnecessary components in library.

    Here is Menu.java.

    package com.hobak.sci;
    
    import com.hobak.sci.DeveloperKey;
    import com.hobak.sci.R;
    import com.google.android.youtube.player.YouTubeBaseActivity;
    import com.google.android.youtube.player.YouTubeInitializationResult;
    import com.google.android.youtube.player.YouTubePlayer;
    import com.google.android.youtube.player.YouTubePlayer.Provider;
    import com.google.android.youtube.player.YouTubePlayerView;
    import android.os.Bundle;
    
    public class Menu extends YouTubeBaseActivity implements
        YouTubePlayer.OnInitializedListener {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.menu);
    
            YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
        youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
        }
    
        @Override
        public void onInitializationSuccess(YouTubePlayer.Provider provider,
            YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            player.cueVideo("2LHv1FPd1Ec");
        }
    }
    
    protected YouTubePlayer.Provider getYouTubePlayerProvider() {
        return (YouTubePlayerView) findViewById(R.id.youtube_view);
    }
    
    @Override
    public void onInitializationFailure(Provider arg0,
            YouTubeInitializationResult arg1) {
        // TODO Auto-generated method stub
    
    }
    
    }
    

    and here is my xml file

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFACD"
        android:orientation="vertical" >
    
    
      <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtube_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
    
    
    
    </LinearLayout>
    

    and here is my logcat

    03-17 15:55:51.260: E/AndroidRuntime(5277): FATAL EXCEPTION: main
    03-17 15:55:51.260: E/AndroidRuntime(5277): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hobak.sci/com.hobak.sci.Menu}: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.google.android.youtube.api.service.START }
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1961)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.app.ActivityThread.access$600(ActivityThread.java:128)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1152)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.os.Handler.dispatchMessage(Handler.java:99)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.os.Looper.loop(Looper.java:137)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.app.ActivityThread.main(ActivityThread.java:4453)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at java.lang.reflect.Method.invokeNative(Native Method)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at java.lang.reflect.Method.invoke(Method.java:511)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at dalvik.system.NativeStart.main(Native Method)
    03-17 15:55:51.260: E/AndroidRuntime(5277): Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.google.android.youtube.api.service.START }
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.app.ContextImpl.bindService(ContextImpl.java:1164)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at com.google.android.youtube.player.internal.r.e(Unknown Source)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at com.google.android.youtube.player.YouTubeBaseActivity$a.a(Unknown Source)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at com.google.android.youtube.player.YouTubePlayerView.initialize(Unknown Source)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at com.hobak.sci.Menu.onCreate(Menu.java:21)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.app.Activity.performCreate(Activity.java:4467)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1925)
    03-17 15:55:51.260: E/AndroidRuntime(5277):     ... 11 more
    
  • Mahesh
    Mahesh over 10 years
    hii i already add the permission for internet but still it gives me error same
  • alexismorin
    alexismorin over 10 years
    @AndroidPower, make sure you clean your project and rebuild it. It happens that code changes in XML files do not automatically trigger Eclipse's autobuild feature.
  • Mahesh
    Mahesh over 10 years
    hi now is play but if youtube player app is not installed in mobile than is not play i want to play youtubevideo without any other app how can i do this
  • alexismorin
    alexismorin over 10 years
    @AndroidPower, I don't think can do that. If you read developers.google.com/youtube/android/player, you'll notice: Note: Users need to run version 4.2.16 of the mobile YouTube app (or higher) to use the API.
  • TapanHP
    TapanHP over 7 years
    Is this issue have any connection with debug mode and release mode? @alexismorin
  • Faisal Shaikh
    Faisal Shaikh almost 7 years
    You saved my several hours. Thank you.