Android: Add Button to YouTubePlayerView

I want to add a YouTubePlayerView button , but don’t know how best to do it. I would like the button to be present only when the user clicks on the screen to call the youtube controls (play / pause, timeline, sharing, etc.) that disappear after a few seconds when the controls disappear. I looked at ViewGroupOverlay , but I'm not sure if this is the best way to do this, and I'm not sure as soon as the button is added to the overlay with the available controls. It seems to me that I should override one of YouTubePlayer or YouTubePlayerViewto know when the controls are visible, but I'm just making a hypothesis here. I am relatively new to android, and it has been a long time since I did something serious in Java. Any direction here would be great if others did not know the exact answer. I looked about two hours before posting this.

package com.example.something.exampletube;

import android.os.Bundle;
import android.view.ViewGroupOverlay;
import android.widget.Toast;

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;

/**
 * Created by Nicholas Dwyer on 4/17/2015.
 * This class is used to play youtube videos
 */
public class PlayerActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
YouTubePlayerView playerView;
ViewGroupOverlay groupOverlay;


@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    setContentView(R.layout.activity_player);

    playerView = (YouTubePlayerView) findViewById(R.id.player_view);
    playerView.initialize(YoutubeConnector.KEY, this);
    groupOverlay = playerView.getOverlay();
}

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean restored) {
    if(!restored) {
        youTubePlayer.cueVideo(getIntent().getStringExtra("VIDEO_ID"));
    }
}

@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
    String errorMessage = "There was an error initializing the YouTubePlayer" + youTubeInitializationResult.toString();
    Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
    //Toast.makeText(this,getString(R.string.failed), Toast.LENGTH_LONG).show();
}

}

+4
source share
2 answers

It is not possible to add buttons as labels above the player, as indicated by Google:

https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayerView

, 200x110 . , . , .

. YouTube Android?

- ( YouTubeVideoView ), . Google , YouTube.

: WebView .

+3

- Exoplayer, . sdk Android, google Android:

http://google.imtqy.com/ExoPlayer/ https://developer.android.com/guide/topics/media/exoplayer.html

Exoplayer , Youtubes.

, Exoplayer Youtube.

0

All Articles