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

时间:2015-04-13 05:35:30

标签: android youtube android-youtube-api

我已经制作了一个youtube api演示,并且myl要求是我要禁用来自YoutubePlayerView(seekbar)的userControlls,我已经搜索并找到了关于它的解决方案,但我不知道如何在我的代码中应用它。可以任何人建议我如何禁用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);

        }
    }

}

2 个答案:

答案 0 :(得分:1)

您可以这样使用YouTubePlayer.PlayerStyle枚举类

player.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);

player.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);

答案 1 :(得分:0)

枚举值

  

公共静态最终YouTubePlayer.PlayerStyle CHROMELESS

     

不显示交互式播放器控件的样式。


  

公共静态最终YouTubePlayer.PlayerStyle DEFAULT

     

默认样式,显示所有交互式控件。


  

公共静态最终YouTubePlayer.PlayerStyle MINIMAL

     

最小样式,仅显示时间栏和播放/暂停控件。

尝试以下方法:

 @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);
}