gpt4 book ai didi

android - YouTubePlayerView 在屏幕方向更改时重新加载视频

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:18:24 26 4
gpt4 key购买 nike

我使用以下 Activity 从我的应用程序启动了一个 YouTube 视频。启动 Activity 时,将播放 youtube 视频。但是当我改变屏幕的方向时,视频没有恢复而是从头开始。这里有什么问题?

package com.example.blahblah;

import android.content.res.Configuration;
import android.os.Bundle;
import android.widget.Toast;

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.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;

public class YTPlayActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {


static private String yt_sk;
static private final String DEVELOPER_KEY = "my-api-key";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.yt_player);
Bundle extras = getIntent().getExtras();
yt_sk = extras.getString("yt_sk");

YouTubePlayerView youTubeView = (YouTubePlayerView)
findViewById(R.id.youtube_view);

youTubeView.initialize(DEVELOPER_KEY, this);

}

@Override

public void onInitializationFailure(Provider provider,
YouTubeInitializationResult error) {

Toast.makeText(this, "Oh no! "+error.toString(),
Toast.LENGTH_LONG).show();

}
@Override

public void onInitializationSuccess(Provider provider, YouTubePlayer player,
boolean wasRestored) {

player.loadVideo(yt_sk);

}



}

最佳答案

在 AndroidManifest 文件中添加了 configChanges,它起作用了。

例如:

 <activity android:label=Activity Name" 
android:configChanges="keyboardHidden|orientation|screenSize"
android:name="com.example.blahblah">

关于android - YouTubePlayerView 在屏幕方向更改时重新加载视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19436776/

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