Теперь пользователь ниже кода в xml:
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="@dimen/_200sdp"
android:layout_margin="@dimen/_5sdp"
android:layout_below="@+id/header"
/>
Java код:
youtube_player_view = findViewById(R.id.youtube_player_view);
private void initVideo(final String videoId) {
youtube_player_view.initialize(getResources().getString(R.string.youtube_api_key), new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean youtube_avalable) {
//youTubePlayerMain = youTubePlayer;
if (!youtube_avalable) {
youTubePlayerMain = youTubePlayer;
youTubePlayerMain.loadVideo(videoId);
youTubePlayerMain.setShowFullscreenButton(false);
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
if (youTubeInitializationResult.isUserRecoverableError()) {
youTubeInitializationResult.getErrorDialog(getApplicationContext(), 1).show();
} else {
Toast.makeText(getApplicationContext(), youTubeInitializationResult.toString(), Toast.LENGTH_LONG).show();
}
}
});
}