是否可以隐藏媒体控制器,除了来自youtube播放器api的播放,暂停和搜索栏

时间:2015-01-21 05:15:24

标签: android youtube-api mediacontroller

我试图通过使用youtube播放器api播放youtube视频,它正在工作,但我想隐藏一些媒体控制器,除了播放,暂停和搜索栏,在我的youtube播放器api有一些不必要的控制器,如设置,fullscree,我不想要这个控制器,因为我的视频不应该导航到youtube,请你帮我解决这个问题

public class MainActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {

    ImageView im;
    private YouTubePlayer YPlayer;
     private static final String YoutubeDeveloperKey = "AIzaSyBWVhXZfBq0S37bzdwMzUtqbkxOAWrVoko";
     private static final int RECOVERY_DIALOG_REQUEST = 1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
        youTubeView.initialize(YoutubeDeveloperKey, this);


        }
        @Override
        public void onInitializationFailure(YouTubePlayer.Provider provider,
        YouTubeInitializationResult errorReason) {
        if (errorReason.isUserRecoverableError()) {
        errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
        } else {
        String errorMessage = String.format(
        "There was an error initializing the YouTubePlayer",
        errorReason.toString());
        Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
        }
        }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == RECOVERY_DIALOG_REQUEST) {
        // Retry initialization if user performed a recovery action
        getYouTubePlayerProvider().initialize(YoutubeDeveloperKey, this);
        }
        }
        protected YouTubePlayer.Provider getYouTubePlayerProvider() {
        return (YouTubePlayerView) findViewById(R.id.youtube_view);
        }
        @Override
        public void onInitializationSuccess(Provider provider,
        YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
        YPlayer = player;
        YPlayer.cueVideo("0vrdgDdPApQ");
        }
        }
}

这是我的xml代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".TruitonYouTubeAPIActivity" >

  <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtube_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

您可以使用YouTubePlayer.PlayerStyle枚举类

youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);

(或)参考此链接

https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayer.PlayerStyle