我正在开发一个Android应用程序,我想在其中制作一些YouTube视频的集合。当我点按任何视频时,我想以全屏横向模式播放这些视频。请帮我。这是代码
MainActivity.java
package com.pss.hotbellydance;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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;
public class MainActivity extends YouTubeBaseActivity {
YouTubePlayerView youTubePlayerView;
public static final String KEY = "AIzaSyDUbG4mpT9FCLhkVi3uRdI1G-Dt9DRXTlU";
public static final String VID_ID = "UVSTNzonj8Q";
YouTubePlayer.OnInitializedListener onInitializedListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
youTubePlayerView = (YouTubePlayerView) findViewById(R.id.video1);
onInitializedListener = new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.loadVideo(VID_ID);
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
};
youTubePlayerView.initialize(KEY,onInitializedListener);
}
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.pss.hotbellydance.MainActivity">
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/video1"
android:layout_width="match_parent"
android:layout_height="250dp">
</com.google.android.youtube.player.YouTubePlayerView>
</LinearLayout>
答案 0 :(得分:0)
将您的youtube活动置于横向模式:
<activity android:name=".MainActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize"/>
或以编程方式:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);