gpt4 book ai didi

android - 默认情况下如何在横向全屏模式下播放youtube数据API视频

转载 作者:行者123 更新时间:2023-12-03 06:13:40 31 4
gpt4 key购买 nike

我正在开发一个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>

最佳答案

将您的youtube Activity 置于横向模式:

<activity  android:name=".MainActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize"/>

或以编程方式:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

关于android - 默认情况下如何在横向全屏模式下播放youtube数据API视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47422359/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com