1. Download our Official Android App: Forums for Android!

Apps Playing youtube video help

Discussion in 'Android Development' started by aSpoon, Aug 15, 2017.

  1. aSpoon

    aSpoon Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    8
    Joined:
    Aug 14, 2017

    Aug 14, 2017
    8
    0
    5
    Im trying to put a youtube video in my app heres some code i did
    Code (Java):
    1.     YouTubePlayerView mYouTubePlayerView2;
    2.     Button btnPlay2;
    3.     YouTubePlayer.OnInitializedListener mOnInitializedListener2;
    4.     @Override
    5.     protected void onCreate(Bundle savedInstanceState) {
    6.         super.onCreate(savedInstanceState);
    7.         setContentView(R.layout.display3);
    8.         Log.d(TAG, "onCreate: Starting.");
    9.         btnPlay2 = (Button) findViewById(R.id.btnPlay2);
    10.         mYouTubePlayerView2 = (YouTubePlayerView) findViewById(R.id.youtubePlayer2);
    11.         mOnInitializedListener2 = new YouTubePlayer.OnInitializedListener() {
    12.             @Override
    13.             public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
    14.                 Log.d(TAG, "onClick: Done initializing.");
    15.                 youTubePlayer.loadVideo("cdCEltQn_IA");
    16.             }
    17.             @Override
    18.             public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
    19.                 Log.d(TAG, "onClick: Failed to initialize.");
    20.             }
    21.         };
    22.         btnPlay2.setOnClickListener(new View.OnClickListener() {
    23.             @Override
    24.             public void onClick(View view) {
    25.                 Log.d(TAG, "onClick: Intializing YouTube Player.");
    26.                 mYouTubePlayerView2.initialize(YTConfig.getApiKey(), mOnInitializedListener2);
    27.             }
    28.         });
    29.     }
    It runs fine when i open the activity and click the play button it says failed to initialize anyone know a fix?
     

    Advertisement

  2. LV426

    LV426 Illegitimi non carborundum
    Moderator
    Rank:
     #21
    Points:
    1,238
    Posts:
    4,831
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    4,831
    6,315
    1,238
    Male
    Software developer
    South West of England
    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)
     
    aSpoon likes this.
  3. aSpoon

    aSpoon Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    8
    Joined:
    Aug 14, 2017

    Aug 14, 2017
    8
    0
    5
    sorry im really bad at this can you add it to my code and resend it please? thank a ton
     
  4. LV426

    LV426 Illegitimi non carborundum
    Moderator
    Rank:
     #21
    Points:
    1,238
    Posts:
    4,831
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    4,831
    6,315
    1,238
    Male
    Software developer
    South West of England
    Oh go on, you can do it. I believe in you!
     
  5. aSpoon

    aSpoon Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    8
    Joined:
    Aug 14, 2017

    Aug 14, 2017
    8
    0
    5
    i already have that i just realized lol now what
     
  6. LV426

    LV426 Illegitimi non carborundum
    Moderator
    Rank:
     #21
    Points:
    1,238
    Posts:
    4,831
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    4,831
    6,315
    1,238
    Male
    Software developer
    South West of England
    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.
     
    aSpoon likes this.
  7. aSpoon

    aSpoon Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    8
    Joined:
    Aug 14, 2017

    Aug 14, 2017
    8
    0
    5
    um... how get to debug mode?
     
  8. LV426

    LV426 Illegitimi non carborundum
    Moderator
    Rank:
     #21
    Points:
    1,238
    Posts:
    4,831
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    4,831
    6,315
    1,238
    Male
    Software developer
    South West of England
    #8 LV426, Aug 21, 2017
    Last edited: Aug 21, 2017
  9. aSpoon

    aSpoon Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    8
    Joined:
    Aug 14, 2017

    Aug 14, 2017
    8
    0
    5
    what does this mean?
     

    Attached Files:

Share This Page

Loading...