-
-
Save medyo/f226b967213c3b8ec6f6bebb5338a492 to your computer and use it in GitHub Desktop.
package com.google.android.youtube.player; | |
/** | |
* Please create this directories schema com.google.android.youtube.player and post the file there | |
*/ | |
import android.os.Bundle; | |
import android.util.AttributeSet; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import androidx.fragment.app.Fragment; | |
import androidx.fragment.app.FragmentActivity; | |
import com.google.android.youtube.player.internal.ab; | |
public class YouTubePlayerSupportFragmentX extends Fragment implements YouTubePlayer.Provider { | |
private final YouTubePlayerSupportFragmentX.a a = new YouTubePlayerSupportFragmentX.a(); | |
private Bundle b; | |
private YouTubePlayerView c; | |
private String d; | |
private YouTubePlayer.OnInitializedListener e; | |
private boolean f; | |
public static YouTubePlayerSupportFragmentX newInstance() { | |
return new YouTubePlayerSupportFragmentX(); | |
} | |
public YouTubePlayerSupportFragmentX() { | |
} | |
public void initialize(String var1, YouTubePlayer.OnInitializedListener var2) { | |
this.d = ab.a(var1, "Developer key cannot be null or empty"); | |
this.e = var2; | |
this.a(); | |
} | |
private void a() { | |
if (this.c != null && this.e != null) { | |
this.c.a(this.f); | |
this.c.a(this.getActivity(), this, this.d, this.e, this.b); | |
this.b = null; | |
this.e = null; | |
} | |
} | |
public void onCreate(Bundle var1) { | |
super.onCreate(var1); | |
this.b = var1 != null ? var1.getBundle("YouTubePlayerSupportFragment.KEY_PLAYER_VIEW_STATE") : null; | |
} | |
public View onCreateView(LayoutInflater var1, ViewGroup var2, Bundle var3) { | |
this.c = new YouTubePlayerView(this.getActivity(), (AttributeSet)null, 0, this.a); | |
this.a(); | |
return this.c; | |
} | |
public void onStart() { | |
super.onStart(); | |
this.c.a(); | |
} | |
public void onResume() { | |
super.onResume(); | |
this.c.b(); | |
} | |
public void onPause() { | |
this.c.c(); | |
super.onPause(); | |
} | |
public void onSaveInstanceState(Bundle var1) { | |
super.onSaveInstanceState(var1); | |
Bundle var2 = this.c != null ? this.c.e() : this.b; | |
var1.putBundle("YouTubePlayerSupportFragment.KEY_PLAYER_VIEW_STATE", var2); | |
} | |
public void onStop() { | |
this.c.d(); | |
super.onStop(); | |
} | |
public void onDestroyView() { | |
this.c.c(this.getActivity().isFinishing()); | |
this.c = null; | |
super.onDestroyView(); | |
} | |
public void onDestroy() { | |
if (this.c != null) { | |
FragmentActivity var1 = this.getActivity(); | |
this.c.b(var1 == null || var1.isFinishing()); | |
} | |
super.onDestroy(); | |
} | |
private final class a implements YouTubePlayerView.b { | |
private a() { | |
} | |
public final void a(YouTubePlayerView var1, String var2, YouTubePlayer.OnInitializedListener var3) { | |
YouTubePlayerSupportFragmentX.this.initialize(var2, YouTubePlayerSupportFragmentX.this.e); | |
} | |
public final void a(YouTubePlayerView var1) { | |
} | |
} | |
} |
@jobayer, it's imported from import com.google.android.youtube.player.internal.ab;
thanks @medyo ,
I don't believed that package folder would worked.
Thanks! it's worked nice
I made a kotlin version for this and have tested it on my projects. Feel free to comment if there is any problem https://gist.github.com/novanto/5ea09bebd683a2bbdd9c4f697b6a6b28
I made a kotlin version for this and have tested it on my projects. Feel free to comment if there is any problem https://gist.github.com/novanto/5ea09bebd683a2bbdd9c4f697b6a6b28
Awesome
Hello, first of all thank you for this awesome contribution. Recently I changed in my app the targetSdkVersion to 30 and then started to see issues. Not able to play videos using sdk 30. I returned to 29 and all works fine.
Hello, first of all thank you for this awesome contribution. Recently I changed in my app the targetSdkVersion to 30 and then started to see issues. Not able to play videos using sdk 30. I returned to 29 and all works fine.
I think the issue is related to package visibility on android 11. Just add these lines below on your manifest - below the closing </application>
tag. Read here for more info
<queries>
<intent>
<action android:name="com.google.android.youtube.api.service.START" />
</intent>
</queries>
At least give variables a meaningful name. It took me time to really understand. By the way thanks
You are genius @medyo, thanks a lot!!!
Great! Thx.
@MAkif06 you have to create the following package schema in your src
📁com
📁 google
📁 android
📁 youtube
📁 player
📄 YouTubePlayerSupportFragmentX.java
Should I transfer other files such as "YouTubeApiServiceUtil" to this schema along with this YouTubePlayerSupportFragmentX ?
@MAkif06 No, no need
@MAkif06 move the content (com.google.android... ) to the main/java
folder
Thank you very much I will try that advice.Have nice day.
Thank you very much.I solved to problem thank to your advices.Have nice day.
Hi @medyo , I'm getting an error here - " Cannot access 'a': it is package-private in 'YouTubePlayerView'", as well as "Cannot access '': it is package-private in 'YouTubePlayerView'". any thoughts on how I can resolve this?
@tscholze yes I did, thanks! Discussion here, but I think it was mainly due to making sure the new folder/package called com.google.android.youtube.player is in the root folder
https://johncodeos.com/how-to-embed-youtube-videos-into-your-android-app-using-kotlin/
thanks buddy!
when I tried to move com.google.android.youtube.player... to java/main folder, it give me alert that com is already exist
Any Solution for Android 13, as this solution is not working on android 13
Any Solution for Android 13, as this solution is not working on android 13
"An error occurred while initializing the YouTube Player"
Any Solution for Android 13, as this solution is not working on android 13
"An error occurred while initializing the YouTube Player"
Getting above mentioned error on Android 13
Does anybody know removing youtube branding image from the Player?
@medyo in line 34, from where we are getting
ab
inab.a(var1, "Developer key cannot be null or empty");
. It is not defined anywhere.