• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Playing youtube video help

aSpoon

Lurker
Im trying to put a youtube video in my app heres some code i did
Java:
    YouTubePlayerView mYouTubePlayerView2;
    Button btnPlay2;
    YouTubePlayer.OnInitializedListener mOnInitializedListener2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.display3);
        Log.d(TAG, "onCreate: Starting.");
        btnPlay2 = (Button) findViewById(R.id.btnPlay2);
        mYouTubePlayerView2 = (YouTubePlayerView) findViewById(R.id.youtubePlayer2);
        mOnInitializedListener2 = new YouTubePlayer.OnInitializedListener() {
            @Override
            public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
                Log.d(TAG, "onClick: Done initializing.");
                youTubePlayer.loadVideo("cdCEltQn_IA");
            }
            @Override
            public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
                Log.d(TAG, "onClick: Failed to initialize.");
            }
        };
        btnPlay2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(TAG, "onClick: Intializing YouTube Player.");
                mYouTubePlayerView2.initialize(YTConfig.getApiKey(), mOnInitializedListener2);
            }
        });
    }
It runs fine when i open the activity and click the play button it says failed to initialize anyone know a fix?
 
I suggest that you look at the parameter value of youTubeInitializationResult. It should tell you why the initialization failure occurred.

public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult)
 
I suggest that you look at the parameter value of youTubeInitializationResult. It should tell you why the initialization failure occurred.

public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult)
sorry im really bad at this can you add it to my code and resend it please? thank a ton
 
Now what? Well you could do a couple of things. Either:

1. Run the app in debug mode, and set a breakpoint at line 19 above. Examine the value of the youTubeInitializationResult variable.
2. Add some code to do something like recover from the failure. What exactly that is depends on the failure reason, which at this point nobody knows, so can't advise on the specific code you would need.
3. Add code to resolve the root cause of the problem, so that the failure doesn't occur. But to do this, you need to know what is causing the failure. At this point we don't have enough information to determine that.

Either way, it's time to roll your sleeves up and debug your app. Only you are in a position to do this, because interactive debugging of code on a Q&A tech forum isn't a practical way of developing code.
 
Now what? Well you could do a couple of things. Either:

1. Run the app in debug mode, and set a breakpoint at line 19 above. Examine the value of the youTubeInitializationResult variable.
2. Add some code to do something like recover from the failure. What exactly that is depends on the failure reason, which at this point nobody knows, so can't advise on the specific code you would need.
3. Add code to resolve the root cause of the problem, so that the failure doesn't occur. But to do this, you need to know what is causing the failure. At this point we don't have enough information to determine that.

Either way, it's time to roll your sleeves up and debug your app. Only you are in a position to do this, because interactive debugging of code on a Q&A tech forum isn't a practical way of developing code.
um... how get to debug mode?
 

Attachments

  • Screen Shot 2017-08-24 at 8.01.57 PM.png
    Screen Shot 2017-08-24 at 8.01.57 PM.png
    60.3 KB · Views: 107
Back
Top Bottom