-- Update 09/05/2016 17:10 -- The problem seems related to the date of publication of the video... In the last week of April I posted many videos on YouTube, those published up to 19:00 of April 27 work properly, while those charged by 21:15 on the same day have the issue discussed, as if between 19 and 21 of April 27 had been introduced a few updates or changes to the videos by YouTube. I tried to load a new video now and this also has the same problem.
I have a strange problem with YouTubeAndroidPlayerAPI.. I use YouTubePlayerSupportFragment (but I have the same problem with YouTubePlayerFragment) to play videos in my app, some video play perfectly, other show the error "There was a problem while playing. Tap to retry.".
When this happen in the Android Monitor I see the YouTube API error:
05-08 11:25:22.145 20521-20521/? E/YouTubeAndroidPlayerAPI: fmt.noneavailable
oae: Video not supported/available
at oab.a(SourceFile:212)
at nvl.a(SourceFile:383)
at nvl.a(SourceFile:706)
at nvr.a(SourceFile:1144
at nsn.onPostExecute(SourceFile:2102)
at android.os.AsyncTask.finish(AsyncTask.java:651)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
If I tap the YouTube icon in the video to play it in the YouTube app, the video is played correctly in the official app.
If the video has monetization active, the ad video is showed normally, at the end the error is showed.
I tried:
- Use YouTubePlayerFragment instead of YouTubePlayerSupportFragment
- Use Activity instead of AppCompatActivity
- Embed the video in an HTML page, it works correctly
- Deactive monetization, nothing changes
- Different keys, one for debugging and one for the release
Thank you very much for helping!
Update 11/05/2016 It seems to be a YouTube bug; the only passable workaround at this time appears to be open the video in the YouTube official app with an intent or replace the player fragment with a WebView. The standard WebView is very limited and will not show the button to bring the video fullscreen. You need to create a class that extend 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, load the video in the WebView:
myWebView.loadUrl("https://www.youtube.com/embed/"+youtube_id);
If you want to adapt the WebView dimensions 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)));
Try updating your YouTube app to version 11.19.56.
来源:https://stackoverflow.com/questions/37098956/youtubeandroidplayerapi-cant-play-some-videos