YouTubePlayerView Initialization Failure
Asked Answered
S

1

7

I have used YouTubePlayerView in My project. But there is a problem while playing the video.

And I tested it in some devices,

  1. Moto lollipop (api 22) --> Shows "unfortunately Youtube has stopped"

  2. Swipe Marshmallow (api 23) --> It keeps on loading and displaying text Ad in left side bottom. But the video doesn't have ad before it.And There is no error or exception, It is showing a warning as, ,

W/System: ClassLoader referenced unknown path: /system/app/YouTube/lib/arm64

I searched in SO. The solutions in ClassLoader referenced unknown path: /data/app/ doesn't work for me. And There is no solution for the issue "video keeps on loading" .

I tried solutions of all related posts, but not suited for my case.

I have used Recyclerview and the item has Youtubeplayerview,

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:background="?android:solidColor"
    android:id="@+id/newsLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <com.google.android.youtube.player.YouTubePlayerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/video"
        android:background="#000"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.5"
        android:orientation="vertical"
        android:padding="4dp">
             <!-- other views -->
    </LinearLayout>

</LinearLayout>

Java code,

holder.video.initialize(MyDa.YoutubeApi, new YouTubePlayer.OnInitializedListener() {
                @Override
                public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
                    youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);
                    youTubePlayer.loadVideo(extractYTId(nhBean.gtURL()));
                    youTubePlayer.play();
                    videoplayer=youTubePlayer;
                }

                @Override
                public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
                    ((Activity)context).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(context,"can't play video",Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });

Can anyone help me!!!

Synchronic answered 3/5, 2018 at 10:28 Comment(10)
show your code and xmlRheumy
@DeveloperHitesh please check edited postSynchronic
have you check your extractYTid is getting correct idRheumy
Yeah the id is not the issueSynchronic
check this https://mcmap.net/q/959739/-struggling-with-youtube-player-support-fragmentRheumy
have you set your api Restrictions none ??Rheumy
@DeveloperHitesh I didn't set any restrictionsSynchronic
check this evenidontknow.com/Working-YouTube-api-android-part2.htmlCavendish
Please post whole stacktraceIloilo
Are you getting this issue on only the above mentioned devices or allPitcher
R
2

Try Like This If this helps

    videoplayer=youTubePlayer;
    videoplayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL)           
    videoplayer.loadVideo(extractYTId(nhBean.gtURL()));
    videoplayer.play();
Rheumy answered 3/5, 2018 at 11:49 Comment(2)
But what is the difference?Synchronic
i have used youtube player view like this so i suggestRheumy

© 2022 - 2024 — McMap. All rights reserved.