Unable to play some Youtube videos using YouTube Android Player API
Asked Answered
F

5

18

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

Friede answered 25/9, 2015 at 14:42 Comment(7)
What style is your YouTubePlayer using?Fustanella
@dextor , it using YouTubePlayer.PlayerStyle.MINIMALFriede
Have you tried others (including NONE)? Just to see if that changes anything.Fustanella
@dextor, will check it now, it has 3 options : CHROMELESS, DEFAULT, MINIMALFriede
Have you tried changing the style? Does that bring to different results? Also, what is the YouTube app version on your device?Fustanella
@dextor , yes, I've tried, no results. My YouTube app version is 10.37.58Friede
https://mcmap.net/q/741965/-upgrade-to-the-latest-version-of-the-android-youtube-api This is my question and answer. I hope it will be help.Companionable
R
13

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

Rockweed answered 1/10, 2015 at 15:8 Comment(0)
F
1

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

Fustanella answered 15/10, 2015 at 19:23 Comment(2)
Tried it, doesn't fix anything. This is really bad, my app is totally useless now to anyone who has updated their Youtube app.Bambara
Nothing happen in Latest Version 1.2.2 i am still waiting for solution.Dunham
S
1

<activity android:name=".ui.activity.PlayerActivity" android:screenOrientation="landscape">

If you didn't add orientation will not work. Orientation is must.otherwise will show as loading, will not play !

Shir answered 4/10, 2020 at 4:32 Comment(0)
S
0

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

Subhead answered 6/10, 2015 at 10:26 Comment(4)
Why are you using a YouTube player jar instead of Gradle?Ascomycete
@Ascomycete where do you see the dependency on Gradle? I have yet to find it.Feat
@Feat I haven't seen people using jars in Android Studio since Android Studio was released :)Ascomycete
@Ascomycete Yes, I am also hugely in favor of Gradle dependencies, but your comment implies that the YouTubePlayer library is available in some way other than a jar, which it is not. developers.google.com/youtube/android/player/downloadsFeat
D
-2

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);
Darb answered 30/9, 2015 at 17:27 Comment(2)
didn't help, these messages occurs when I use YouTubePlayerSupportFragment, with YouTubePlayerFragment works fine. But my whole app buit with AppCompat/Support fragmentsFriede
irrelevant answerSellingplater

© 2022 - 2024 — McMap. All rights reserved.