我正在尝试使用 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>
YouTubePlayer.PlayerStyle枚举类,
youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);
(或)请参阅此链接
https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayer.PlayerStyle