gpt4 book ai didi

android - YouTube 播放器播放 2 秒后全屏停止

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:52:56 25 4
gpt4 key购买 nike

我目前面临两个主要问题,

  1. 我正在使用 YouTube 播放器,当它全屏播放时,会播放 1-2 秒然后停止。

  2. 当我点击中间的“播放”按钮时,它又开始缓冲了。即使灰色条填充到它的中心。

这些问题不会出现在纵向模式下。

这是我的类(class),就像有点不同的 youtube api 演示

public class Video extends YouTubeFailureRecoveryActivity implements YouTubePlayer.OnFullscreenListener, Utils.OnGetUrlListener, View.OnClickListener {

static int AUTO_PLAY_DELAY = 1000;

static final int PORTRAIT_ORIENTATION = Build.VERSION.SDK_INT < 9
? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;

private LinearLayout mRootLayout;

/**
* * Youtube ***
*/
YouTubePlayerView mPlayerView;
YouTubePlayer mPlayer;
boolean mIsFullscreen;
String urlID;

/**
* * My ***
*/
RelativeLayout mContainer;
ImageView mBtPlay;
boolean mIsNeedSetFlags;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils.getInstance().setActivity(this);

setContentView(R.layout.video_main);
mIsNeedSetFlags = true;



mRootLayout = (LinearLayout) findViewById(R.id.video_root_layout);

mContainer = (RelativeLayout) findViewById(R.id.container);

mBtPlay = (ImageView) findViewById(R.id.video_play);
mBtPlay.setVisibility(View.INVISIBLE);

mPlayerView = (YouTubePlayerView) findViewById(R.id.player);

Intent intent = getIntent();


doLayout();
}


@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
mPlayer = player;

player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
player.setOnFullscreenListener(this);

if (mIsNeedSetFlags) {
mIsNeedSetFlags = false;
int controlFlags = player.getFullscreenControlFlags();
setRequestedOrientation(PORTRAIT_ORIENTATION);
controlFlags |= YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
player.setFullscreenControlFlags(controlFlags);
}

if (!wasRestored) {
player.cueVideo(urlID);
}
}

@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return mPlayerView;
}

private void doLayout() {
LinearLayout.LayoutParams playerParams = (LinearLayout.LayoutParams) mPlayerView.getLayoutParams();
if (mIsFullscreen) {
playerParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
playerParams.height = LinearLayout.LayoutParams.MATCH_PARENT;

mParallaxScrollView.setVisibility(View.GONE);
} else {
mParallaxScrollView.setVisibility(View.VISIBLE);

if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
ViewGroup.LayoutParams otherViewsParams = mParallaxScrollView.getLayoutParams();
playerParams.width = otherViewsParams.width = MATCH_PARENT;
playerParams.height = WRAP_CONTENT;
mRootLayout.setOrientation(LinearLayout.VERTICAL);
}
}
mPlayerView.setLayoutParams(playerParams);
}

@Override
public void onFullscreen(boolean isFullscreen) {
mIsFullscreen = isFullscreen;
showPlayerAndPlay();
doLayout();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
doLayout();
}

@Override
public void onGetUrlFinished(String videoUrl) {
urlID = videoUrl;
mBtPlay.setVisibility(View.VISIBLE);
mBtPlay.setOnClickListener(this);
mPlayerView.initialize(Utils.YOU_TUBE_DEV_KEY, this);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.video_play:
showPlayerAndPlay();
break;
}
}


private void showPlayerAndPlay() {
mPlayerView.setVisibility(View.VISIBLE);
mBtPlay.setVisibility(View.INVISIBLE);

if (!mPlayer.isPlaying())
new android.os.Handler().postDelayed(new Runnable() {
@Override
public void run() {
mPlayer.play();
}
}, AUTO_PLAY_DELAY);
}
}

最佳答案

YouTube 不允许其他 View 覆盖其播放器 View 。

如果您检查日志,您还会看到一条警告消息,指出此限制,以及有关哪个 View (其 ID)和重叠区域的更多信息。

关于android - YouTube 播放器播放 2 秒后全屏停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29874055/

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