Embed config is not supported in RemoteEmbeddedPlayer? - android

Whenever I'm trying to open Youtube player in my app, onInitializationSuccess() function is always called. But it shows a blank screen.
First this error appears:
W/YouTubeAndroidPlayerAPI: Forcefully created overlay:affq#82a17f5 helper:Lazy#9b7098a view:null status: ....... {...}
and then:
E/YouTubeAndroidPlayerAPI: Embed config is not supported in RemoteEmbeddedPlayer.
Here is my code:
FragmentManager fragmentManager = ((AppCompatActivity)this.context).getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment youtubeFragment = new YouTubePlayerSupportFragment();
fragmentManager.beginTransaction().add(R.id.GlideLayout ,youtubeFragment).commit();
utubevw = (YouTubePlayerSupportFragment) youtubeFragment;
utubecontainer = imageLayout.findViewById(R.id.youtubecontainer);
utubecontainer.setVisibility(View.VISIBLE);
mOnInitializeListener = new YouTubePlayer.OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVideo("_8kExcHqFi4");
Log.i("youtube", "Successful");
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.i("youtube:Fail", youTubeInitializationResult.toString());
}
};
utubevw.initialize(String.valueOf(R.string.googleapikey), mOnInitializeListener);
Searched everywhere, even posted in Github, but couldn't find a solution.
FYI - I don't want to use Webview to play Youtube.

I had the same problem just now and i was able to solve it by removing all possible overlaying views.
I had a FAB just closely overlaying the youtube fragment. After moving the FAB away the error was fixed.

Try using youTubePlayer.loadVideo(" ") instead of youTubePlayer.cueVideo(" ") to auto play the video when the fragment is started.
According to the docs, if you use the cueVideo() function, you need to call play() or it does not download any of the video stream. Whereas the loadVideo() auto plays the video.

I tried the answer of #PeterOla, it worked for sometime but after sometime the error came back, and after hours of struggle, i found that i had to parse just the key url (without the youtube/) in the youTubePlayer.cueVideo(""), and it worked well for me.

Related

YouTubeAndroidPlayerApi video not playing when id passed from recycleview onClick listener

When I pass youtube ID from recycleview onClick then it shows "This video is unavailable". But same video id works fine when I hard code it. I tried every possible way but could not find any solution. Please, help if anyone can.
This is the code for sending video key,
intent.putExtra("vUrl", adListModel.getUrl());
Getting the video key,
vUrl = getIntent().getStringExtra("vUrl");
Here, I am trying to load video from the video key,
youTubePlayerView.initialize(getResources().getString(R.string.google_api_key), new YouTubePlayer.OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
String videoId = vUrl;
Log.e("YOUTUBE_KEYS", videoId);
youTubePlayer.cueVideo(videoId);
youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
youTubePlayer.play();
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});

Embed YouTube live stream in android app

I'm trying to embed a live stream to android app. This code works perfect for other videos but when I put the URL code of live stream channel it is unable to load. It just keeps on loading. Suggest me something or is there any other API which I need to use for embedding live stream.
onInitializedListener = new YouTubePlayer.OnInitializedListener() {
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.("5kbU-C0FxqA");
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
};
First video id out-of-date so you need to replace another one and check agein
Also i think your code should be like below
onCreate
YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player);
youTubePlayerView.initialize(getString(R.string.google_developer_api_key), this);
OnInitializedListener
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.loadVideo(""); // your video id
youTubePlayer.play();
}
If you can't make it work with the YouTubePlayer API, you may consider using this alternative player: android-youtube-player.
This is all you need to do to play a live video:
Add the player to your XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.pierfrancescosoffritti.androidyoutubeplayer.player.YouTubePlayerView
android:id="#+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Initialize the player and play a video:
YouTubePlayerView youtubePlayerView = findViewById(R.id.youtube_player_view);
getLifecycle().addObserver(youtubePlayerView);
youtubePlayerView.getPlayerUIController().enableLiveVideoUI(true);
youtubePlayerView.initialize(new YouTubePlayerInitListener() {
#Override
public void onInitSuccess(#NonNull final YouTubePlayer initializedYouTubePlayer) {
initializedYouTubePlayer.addListener(new AbstractYouTubePlayerListener() {
#Override
public void onReady() {
String videoId = "2ccaHpy5Ewo";
initializedYouTubePlayer.loadVideo(videoId, 0);
}
});
}
}, true);
You can see a working example in the sample app.

youtube video 400 network when try to play video

I am try to play video using youtube video API
When I put static ID means declare ID in file at that time code is working.
But when I try to fetch ID from getIntent() I also got ID but video not play.
I got There was problem with network.
Below is my code. Its working in this condition.
public String VIDEO = "QqnBjKnwCwE";
youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(DEVELOPER_KEY, Videosshow.this);
#Override
public void onInitializationFailure(Provider provider,
YouTubeInitializationResult error) {
Toast.makeText(this, "Oh no! " + error.toString(), Toast.LENGTH_LONG)
.show();
}
#Override
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
player.loadVideo(String.valueOf( VIDEO));
}
Now When I used
Bundle data = getIntent().getExtras();
VIDEO=data.getString("videourl");
youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(DEVELOPER_KEY, Videosshow.this);
not working I got 400 Network problem error
Check your id .I think there is space in id or youtube url either start or end .I have similar problem and solved by this .You should also try .It may be help for if you have setup all properly .
I figured out that the id I was sending was incorrect, it had an extra = (say =hdeFZ6nt9tc)which was not to be sent. The problem occurred as I was extracting it from the youtube's actual URL(say https://www.youtube.com/watch?v=hdeFZ6nt9tc). I hope even you too might have been sending the wrong id.
Double check it again even if you are pretty sure.
What I think is youtube must send a 404(which generally refers to "Page Not Found" on the web) for such requests.
I had same the problem but retrieving video id from url solved my problem.
String video_id=jsonObject.getString("id");
Thank You ritesh.

android youtube api not playing videos as expected

i am trying to embed a youtube api for android, everything for good except the fact, that video play for a one second only and then stop automaticly. but when i am going to the fullScreenMode, the video playing as expected.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_show);
ivThumbnail = (ImageView) findViewById(R.id.ivThumbnail);
tv = (ImageView) findViewById(R.id.tv);
Intent i = getIntent();
screenCase = i.getIntExtra("screenCase", -1);
selectedVideoId = Splash.playlists[screenCase].getItems().get(0).getVideo().getId();
setProperTvImage();
createButtons();
ivThumbnail.setImageBitmap(Splash.playlists[screenCase]
.thumbnails[0]);
youtubeLV = (ListView)findViewById(R.id.lvPlaylist);
adapter = new MyYoutubeListAdapter(this, Splash.playlists[screenCase].getItems(), screenCase);
youtubeLV.setAdapter(adapter);
youtubeLV.setOnItemClickListener(this);
youtubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youtubePlayerView.initialize(DeveloperKey.DEVELOPER_KEY, this); //init Player
}
onInitializationSuccess
public void onInitializationSuccess(Provider arg0, YouTubePlayer _player,
boolean wasRestored) {
this.player = _player;
//player.setPlayerStyle(PlayerStyle.CHROMELESS);
if(!wasRestored){
playVideoAtSelection();
}
}
and finally playVideAtSelection methode
private void playVideoAtSelection() {
if(player != null){
Log.e("player ", "not null");
player.cueVideo(selectedVideoId);
}else{
Log.e("player ", "null");
}
}
Any suggestions?
Well, its a bit late for answer, but someone might stumble on this post and might get an insight.
I was facing the same issue and 1st option below solved my problem.
After a lot of search regarding the similar issue, I came across two things.
1) Check if your YoutubePlayerView (in activity XML) has padding option. Remove the padding if its there.
2) As per youtube Api documentation, the minimum size specified is 200 x 110 dp for YoutubePlayerView. Make suitable changes in size if that is the case.
Hope it helps somebody.

video playback displays blank screen with only audio?

I have to develop an one android application.
here i have to play the youtube video on full screen mode and normal mode.
i have using youtubeplayerfragment.
Here the video is playing well on fullscreen mode.
The Same video is didnot play on normal mode.
My Exact problem is,
When I try to play the video, all I get is blank video but I get all the audio and subtitles.
If I hit the back button, I see the last video frame before the video player closes.
Why am facing these issue ???
please give me any solution ??
am using following xml code:
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:id="#+id/youtube_fragment"
android:layout_width="match_parent"
android:layout_below="#+id/title"
android:layout_height="wrap_content"/>
This is activity code:
_Video = articlevideo.substring(1);
FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
YouTubePlayerSupportFragment fragment = new YouTubePlayerSupportFragment();
fragmentTransaction.add(R.id.youtube_fragment, fragment);
fragmentTransaction.commit();
fragment.initialize(DeveloperKey.DEVELOPER_KEY, new OnInitializedListener() {
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
player.cueVideo(_Video);
}
}
private static final int RECOVERY_DIALOG_REQUEST = 1;
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult errorReason) {
if (errorReason.isUserRecoverableError()) {
errorReason.getErrorDialog(getActivity(), RECOVERY_DIALOG_REQUEST).show();
} else {
String errorMessage = String.format(getString(R.string.error_player), errorReason.toString());
Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_LONG).show();
}
}
});
Whats wrong in my code .please give me any suggestions .
You can check YouTube Direct Lite App as a reference.
While switching to full screen or orintation change, activity is killed and created again in Android. So you may need something like
android:configChanges="orientation|screenSize" >
Check the manifest for it.

Categories

Resources