Unable to play some Youtube videos using YouTube Android Player API

懵懂的女人 提交于 2019-11-27 21:13:52

问题


For example this video can't be played with Youtube player API : https://www.youtube.com/watch?v=OLK1efdt3n8 (other videos from search response works ok)

I get the following messages :

09-25 17:18:50.226  24280-24280/com.mypackagename W/YouTubeAndroidPlayerAPI﹕ Cannot load modern controls UI. Upgrade to the latest version of the Android YouTube API.
09-25 17:19:05.911  24280-24280/com.mypackagename E/YoutubePlayerFragment﹕ video error : INTERNAL_ERROR

YouTubePlayer API version : 1.2.1 (latest)

YouTube app on device is up to date and able to play this video

Video parameters : videoEmbeddable=true videoSyndicated=true


回答1:


For me the issue is that I am able to play the video only once but after that YouTubePlayer doesn't play any video and I hope there are many other people who are also facing similar issues with the YouTubeAndroidPlayerAPI. I think the latest youtube app (version 10.37.58) and YouTubeAndroidPlayerAPI 1.2.1 are not compatible.

To best of my knowledge the only thing you can do currently to solve this problem is downgrade your youtube app installed on the device to 10.36.52 or below. (you can get it from apk mirror)

From what I have noticed while working with YouTubeAndroidPlayerAPI is that with the youtube version 10.36.52 it throws warning messages "Cannot load modern controls UI. Upgrade to the latest version of the Android YouTube API." on the logcat everytime I try to play a video but otherwise works fine. And with version 10.35.53 and below no such warning message is thrown.

Reason: I am not sure but I think this has something to do with the huge memory leak issue with the YoutubePlayerSupport fragment in YouTubeAndroidPlayerAPI 1.2.1 which was widely known and reported in google data api issue tracker. It was finally fixed last month on 1st September (at least that's what the current status says) after a year since it was reported (surprised to see what took google so long). However google hasn't rolled out the new version of YouTubeAndroidPlayerAPI with the fix yet. So maybe they fixed that memory issue in the youtube app in September which some how broke the functionality of YouTubeAndroidPlayerAPI 1.2.1 in some way (since YouTubeAndroidPlayerAPI directly depends on the youtube app to work).




回答2:


Version 1.2.2 of the YouTube Player APIs has just been released. It might address the video playback issue that you are experiencing.




回答3:


Hey this is what i'm implementing in my app for you tube video play

    public class Youtubevideo  extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener
{

    public static final String API_KEY = "Use Your API key For youtube api";

    //http://youtu.be/<VIDEO_ID>
      //sample video id
    public  String VIDEO_ID = "abcdefgh";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /** attaching layout xml **/
        setContentView(R.layout.youtubevideo);
       Intent dataReceived = getIntent();
        if(dataReceived != null)
        {
           VIDEO_ID = dataReceived.getStringExtra("url");

        }
        /** Initializing YouTube player view **/
        YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player);
        youTubePlayerView.initialize(API_KEY, this);
    }

    @Override
    public void onInitializationFailure(Provider provider, YouTubeInitializationResult result) {
        Toast.makeText(this, "Failured to Initialize!", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
        /** add listeners to YouTubePlayer instance **/
        //player.setPlayerStateChangeListener(playerStateChangeListener);
        //player.setPlaybackEventListener(playbackEventListener);
        player.setFullscreen(true);
        player.setShowFullscreenButton(true);
        /** Start buffering **/
        if (!wasRestored) {
            player.cueVideo(VIDEO_ID);
        }
    }

    private PlaybackEventListener playbackEventListener = new PlaybackEventListener() {

        @Override
        public void onBuffering(boolean arg0) {
        }

        @Override
        public void onPaused() {
        }

        @Override
        public void onPlaying() {
        }

        @Override
        public void onSeekTo(int arg0) {
        }

        @Override
        public void onStopped() {
        }

    };

    private PlayerStateChangeListener playerStateChangeListener = new PlayerStateChangeListener() {

        @Override
        public void onAdStarted() {
        }

        @Override
        public void onError(ErrorReason arg0) {
        }

        @Override
        public void onLoaded(String arg0) {
        }

        @Override
        public void onLoading() {
        }

        @Override
        public void onVideoEnded() {
        }

        @Override
        public void onVideoStarted() {
        }
    };


}

and xml will be like:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtube_player"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:padding="5dp" />

</LinearLayout>

and in build.gradle use the Youtube jar lib openly available:

compile files('libs/YouTubeAndroidPlayerApi.jar')

hope this will help. :)




回答4:


This is weird! I can only suggest you to play with some flags and see if some combination fix the problem. I'll start with the following:

youtubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);


来源:https://stackoverflow.com/questions/32784730/unable-to-play-some-youtube-videos-using-youtube-android-player-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!