YouTube Android Player API API INTERNAL_ERROR for multiple videos

Using a sample YouTube code for YouTube Android players (version 1.2.2), if I change any of the video IDs to the one I uploaded (for example, β€œQVikru_w2hQ” or β€œu1n6E81rm80”), the thumbnail is uploaded to the player, but when I press play the player transitions to the onError function using YouTubePlayer.ErrorReason.INTERNAL_ERROR. A message will appear with the message "There was a problem during the game. Press to try again." Playing these videos on the YouTube website or our iOS app does not cause problems. Original video samples are perfectly reproduced using my developer key.

I am experiencing this problem on several devices, including the Nexus 5X (android 6.0.1) with the YouTube app version currently at 11.13.56.

Has anyone else encountered a similar problem?

I also posted a potential google data api error report.

+7
android youtube android-youtube-api
source share
2 answers

WebView seems like a good solution. Since I was in a hurry and needed a quick fix, I used the source code from this github project:

https://github.com/theScrabi/NewPipe

This code is independent of the Youtube API. This is a pure website analysis. All my videos work with the solution as fast as before.

The whole project is a functional application, but you can dive inside and take what you need. I used a snippet that embeds a video thumbnail and full-screen player activity.

Kudos to the author of the project.

+2
source share

This seems to be a YouTube bug, watching YouTubeAndroidPlayerAPI cannot play some videos for the detailed information I collected.

the only workaround available at this time seems to open the video in the official YouTube app with the intent or replace a fragment of the WebView player. I preferred this second solution.

The standard WebView is very limited and will not show a button for full-screen video viewing. You need to create a class that extends WebChromeClient:

public class MyWebChromeClient extends WebChromeClient { FrameLayout.LayoutParams LayoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); @Override public void onShowCustomView(View view, CustomViewCallback callback) { if (mCustomView != null) { callback.onCustomViewHidden(); return; } mContentView = (LinearLayout) findViewById(R.id.scheda_video_activity); mContentView.setVisibility(View.GONE); mCustomViewContainer = new FrameLayout(SchedaVideoActivity.this); mCustomViewContainer.setLayoutParams(LayoutParameters); mCustomViewContainer.setBackgroundResource(android.R.color.black); view.setLayoutParams(LayoutParameters); mCustomViewContainer.addView(view); mCustomView = view; mCustomViewCallback = callback; mCustomViewContainer.setVisibility(View.VISIBLE); setContentView(mCustomViewContainer); } @Override public void onHideCustomView() { if (mCustomView == null) { return; } else { mCustomView.setVisibility(View.GONE); mCustomViewContainer.removeView(mCustomView); mCustomView = null; mCustomViewContainer.setVisibility(View.GONE); mCustomViewCallback.onCustomViewHidden(); mContentView.setVisibility(View.VISIBLE); setContentView(mContentView); } } } 

and then initialize the webview:

 WebView myWebView = (WebView)findViewById(R.id.webview); MyWebChromeClient mWebChromeClient = new MyWebChromeClient(); myWebView.setWebChromeClient(mWebChromeClient); myWebView.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } }); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); 

Finally, upload the video to WebView:

 myWebView.loadUrl("https://www.youtube.com/embed/"+youtube_id); 

If you want to adapt the dimensions of the WebView to the YouTube player, you can do this:

 Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); myWebView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int)Math.round(size.x/1.77))); 
0
source share

All Articles