Open umanusorn opened 3 years ago
Also init by addYouTubePlayerListener
then
youTubePlayer.loadOrCueVideo(
lifecycle,
videoId,
0f
)
still got Video Unavailable
but it work fine if hard coded in xml
Try setting enableAutomaticInitialization
to false in the xml.
Ok so I tried to set that to false in both in the XML and programmatically. Here's how I init the player.
YoutubePlayerFragment player = YoutubePlayerFragment.getInstance();
webView = streamPlayer.findViewById(R.id.youtube_fragment);
YouTubePlayerListener listener = new AbstractYouTubePlayerListener(){};
IFramePlayerOptions options = new IFramePlayerOptions.Builder().controls(0).build();
webView.setEnableAutomaticInitialization(false);
webView.initialize(listener, options);
webView.getYouTubePlayerWhenReady(youTubePlayer -> {
youTubePlayer.addListener(tracker);
youTubePlayer.cueVideo("xF3eTzxELT4",0.0F);
video = Optional.of(youTubePlayer);
});
And here's the XML for the YouTubeplayer element
//Omitted the linearlayout parent code just for neatness
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtube_fragment"
android:name="com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView"
android:layout_width="match_parent"
android:layout_height="241dp"
android:background="@android:color/black"
tools:ignore="Instantiatable" />
So like I say, I've set setEnableAutomaticInitialization to false in both my class file and in the XML and in both cases I still get the video unavailable error.
I did find this error in the android logs, since it references chromium I thought it could be related to this IFrame player and the current issue I'm having.
I/chromium: [INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'ch-ua-form-factor'.", source: (0)
. It seems to be related to this stackoverflow question. Is there a way for me to bypass this or do you account for it in the library?
It doesn't seem like you set enableAutomaticInitialization
to false in XML, can you try?
Ok so I changed it to this: XML:
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtube_fragment"
android:name="com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView"
android:layout_width="match_parent"
android:layout_height="241dp"
android:background="@android:color/black"
app:enableAutomaticInitialization="false"
tools:ignore="Instantiatable" />
and removed that line in the Java class file:
try {
YouTubePlayerListener listener = new AbstractYouTubePlayerListener(){};
IFramePlayerOptions options = new IFramePlayerOptions.Builder().controls(0).build();
webView.initialize(listener, options);
webView.getYouTubePlayerWhenReady(youTubePlayer -> {
youTubePlayer.addListener(tracker);
youTubePlayer.cueVideo(String.valueOf(R.string.yt_test_video_a),0.0F);
video = Optional.of(youTubePlayer);
});
} catch (IllegalStateException e) {
UnisonMobileLog.e("YoutubePlayerFragment", "Exception initialising youtube webview.", e);
}
It seems that the issue persists. Do you maybe know of a way to get more info about why the video is unavailable from YouTube itself? There are no errors in the android logs
Can you try to replicate the issue in the sample app? That would let us know if the issue is specific to your implementation or not.
As for getting more debug info from YouTube, I don't think they provide ways for doing that.
I am having the same problem tried this app:enableAutomaticInitialization="false" but still facing the same problem
youtubePlayerView = YouTubePlayerView(requireContext())
youtubePlayerView?.enableAutomaticInitialization = false
dataBinding?.youtubePlayerLayout?.addView(youtubePlayerView)
Frame layout in which it is get inflated
<FrameLayout
android:id="@+id/youtubePlayerLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Have checked with latest version of player
Can anyone help ?
Can you show a more complete example? you are not loading/cueing the vide in this snippet.
Ok so I changed it to this: XML:
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView android:id="@+id/youtube_fragment" android:name="com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView" android:layout_width="match_parent" android:layout_height="241dp" android:background="@android:color/black" app:enableAutomaticInitialization="false" tools:ignore="Instantiatable" />
and removed that line in the Java class file:
try { YouTubePlayerListener listener = new AbstractYouTubePlayerListener(){}; IFramePlayerOptions options = new IFramePlayerOptions.Builder().controls(0).build(); webView.initialize(listener, options); webView.getYouTubePlayerWhenReady(youTubePlayer -> { youTubePlayer.addListener(tracker); youTubePlayer.cueVideo(String.valueOf(R.string.yt_test_video_a),0.0F); video = Optional.of(youTubePlayer); }); } catch (IllegalStateException e) { UnisonMobileLog.e("YoutubePlayerFragment", "Exception initialising youtube webview.", e); }
It seems that the issue persists. Do you maybe know of a way to get more info about why the video is unavailable from YouTube itself? There are no errors in the android logs
Just regarding this, there is no issue with the library in my code snippet here, my problem was that I was using String.valueOf() on an integer resource (R.string.yt_test_video is an int), so it was just returning the integer value of the resource as a string (i.e "22563") instead of the actual string value of the video ("dQw4w9WgXcQ"). Changing that fixed it.
The video work fine with xml
but when programmatically loadOrCueVideo got this video is unavailable Got this video is unavailable when programmatically loadOrCueVideo
Did I do something wrong?