Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTubePlayerView Initialization Failure

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

like image 488
Jyoti JK Avatar asked May 03 '18 10:05

Jyoti JK


1 Answers

Try Like This If this helps

    videoplayer=youTubePlayer;
    videoplayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL)           
    videoplayer.loadVideo(extractYTId(nhBean.gtURL()));
    videoplayer.play();
like image 85
Developer Hitesh Avatar answered Nov 14 '22 23:11

Developer Hitesh