YouTubeAndroidPlayerAPI无法播放某些视频 [英] YouTubeAndroidPlayerAPI can't play some videos

查看:88
本文介绍了YouTubeAndroidPlayerAPI无法播放某些视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-更新09/05/2016 17:10-问题似乎与该视频的发布日期有关.在4月的最后一周,我在YouTube上发布了许多视频,直到4月27日19:00为止发布的那些视频都可以正常工作,而在21:15之前按当天讨论了这个问题,好像YouTube在4月27日至21日之间对视频进行了一些更新或更改.我现在尝试加载新视频,这也有同样的问题.

-- 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.

我在使用YouTubeAndroidPlayerAPI时遇到了一个奇怪的问题.我使用YouTubePlayerSupportFragment(但我在使用YouTubePlayerFragment时也遇到了同样的问题)在我的应用中播放视频,某些视频播放完美,其他则显示错误播放时出现问题.重试.".

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.".

在Android监视器中发生这种情况时,我会看到YouTube API错误:

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)

如果我点击视频中的YouTube图标以在YouTube应用中播放,则该视频可以在官方应用中正确播放.

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.

我尝试过:

  • 使用YouTubePlayerFragment代替YouTubePlayerSupportFragment
  • 使用活动代替AppCompatActivity
  • 将视频嵌入HTML页面,即可正常运行
  • 无效货币化,没有任何变化
  • 不同的键,一个用于调试,一个用于发布

非常感谢您的帮助!

更新11/05/2016 似乎是一个YouTube错误;目前唯一可行的解​​决方法似乎是故意打开YouTube官方应用中的视频,或将播放器片段替换为WebView.标准的WebView十分有限,不会显示使视频全屏显示的按钮.您需要创建一个扩展WebChromeClient的类:

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);
        }
    }
}

然后初始化WebView:

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);

最后,将视频加载到WebView中:

Finally, load the video in the WebView:

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


如果要使WebView尺寸适应YouTube播放器,可以执行以下操作:


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)));

推荐答案

尝试将您的YouTube应用更新到版本11.19.56.

Try updating your YouTube app to version 11.19.56.

这篇关于YouTubeAndroidPlayerAPI无法播放某些视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆