如何在 android 中禁用 youtube Player View 的控件?

How to disable the controlls of youtube Player View in android?

我做了一个 youtube api 演示,我的要求是我想从 YoutubePlayerView(seekbar) 禁用 userControlls,我已经搜索并找到了解决方案,但我不知道如何申请在我的 code.Can 中有人建议我如何在 android 中禁用 youtube 播放器视图中的搜索栏?

我的代码如下:

代码

public class VideoActivity extends YouTubeBaseActivity implements
        OnClickListener, YouTubePlayer.OnInitializedListener {
    Button btn_toprated;
    TextView tv_site;
    TextView tv_guide;
    public static final String API_KEY = "AIzaSyBV-3VbYw-ljgkj9tDg5pOVEAE8hNmG6q8";
    public static final String VIDEO_ID = "1QydBspryNE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.video_activity);
        super.onCreate(savedInstanceState);
        init();
        PlayerStyle style = PlayerStyle.CHROMELESS;

    }

    void init() {

        btn_toprated = (Button) findViewById(R.id.btn_toprated);
        tv_guide = (TextView) findViewById(R.id.tv_guide);
        tv_site = (TextView) findViewById(R.id.tv_site);
        btn_toprated.setOnClickListener(this);
        tv_guide.setOnClickListener(this);
        tv_site.setOnClickListener(this);

        YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtubeplayerview);

        youTubePlayerView.initialize(API_KEY, this);
    }

    @Override
    public void onClick(View v) {
        Intent i;
        switch (v.getId()) {

        case R.id.tv_guide:
            i = new Intent(VideoActivity.this, GuideActivity.class);
            startActivity(i);
            break;
        case R.id.tv_site:
            String url = "http://www.system500.com";
            i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
            break;
        case R.id.btn_toprated:
            i = new Intent(VideoActivity.this, TopRatedActivity.class);
            startActivity(i);
            break;
        }
    }

    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onInitializationFailure(Provider provider,
            YouTubeInitializationResult result) {
        Toast.makeText(getApplicationContext(), "onInitializationFailure()",
                Toast.LENGTH_LONG).show();
    }

    @Override
    public void onInitializationSuccess(Provider provider,
            YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            player.cueVideo(VIDEO_ID);

        }
    }

}

您可以通过这种方式使用 YouTubePlayer.PlayerStyle 枚举 class

player.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);

player.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);

枚举值

public static final YouTubePlayer.PlayerStyle CHROMELESS

A style that shows no interactive player controls.


public static final YouTubePlayer.PlayerStyle DEFAULT

The default style, showing all interactive controls.


public static final YouTubePlayer.PlayerStyle MINIMAL

A minimal style, showing only a time bar and play/pause controls.

尝试以下操作:

 @Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {
    Toast.makeText(this, "onInitializationSuccess!", Toast.LENGTH_SHORT).show();
    mYoutubePlayer = youTubePlayer;
    if (youTubePlayer == null) 
        return;
    
    // Start buffering
    if (!wasRestored) {
        youTubePlayer.cueVideo(VIDEO_ID);
    }
    youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
}