11

-- 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)));
frabbe
  • 111
  • 1
  • 6
  • Some updates: I have down downgraded the YouTube app to the version 11.10.60 (see the answers below) but the problem remains; so I downgraded to tge factory version, 10.28.60 and I can't see any video, I receive the error DEVELOPER_KEY_INVALID. – frabbe May 09 '16 at 13:25
  • I don't know if it can help but I have this issue only with recent videos uploaded on Youtube. Maybe a recent format change can be causing this? – Sergio Carvalho May 09 '16 at 14:41
  • 1
    Yes, 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. – frabbe May 09 '16 at 15:11
  • 1
    @frabbe playing a video with finishOnEnd = false will work .. but the problem is that user will stay in YT app when playback stops. I hope its a temporary problem, on the other hand i'm also thinking of some temporary solution (wrapping embed html in dialog fragment or something). Application update will be faster then fix from YT. – bajicdusko May 09 '16 at 18:25
  • @bajicdusko open the video in the youtube app seems a good chance, you could try load the video and on error launch youtube app. – frabbe May 10 '16 at 15:44
  • @frabbe i'm not sure that you will have any error callback from YouTubeIntents, hence no error could be caught. Before playback initialization i was inspecting YouTubeIntents.isYouTubeInstalled(context) && YouTubeIntents.canResolvePlayVideoIntent(context) and it was true. Anyway, i'll remove YouTubeIntents. Instead, activity without actionbar, transparent background, centered webview and inject embed. Hacky but works ok. – bajicdusko May 10 '16 at 16:08
  • 1
    @bajicdusko Yes, it's possible intercept the errore creating a class that implements `YouTubePlayer.PlayerStateChangeListener` and it to the player with `player.setPlayerStateChangeListener(myPlayerStateChangeListener);` The `onError` function return `INTERNAL_ERROR` in this case. But this not solve the problem, because I can launch YouTube app from here but when i return back to my app after watching the video the youtube fragment, only on pause, play again firing the error and so on, in an infinite loop.It is much better integrate a WebView as suggested by you. – frabbe May 11 '16 at 14:54
  • I have posted a potential bug report on google data api issue tracker: https://code.google.com/p/gdata-issues/issues/detail?id=8248&thanks=8248&ts=1462356613 – Jon G May 11 '16 at 16:52
  • Yes, I saw the link in your question like this and I immediately signed the bug report ;) – frabbe May 12 '16 at 16:48

1 Answers1

0

Try updating your YouTube app to version 11.19.56.