gpt4 book ai didi

android - Android上的恢复 Activity 时YouTube播放器崩溃异常

转载 作者:行者123 更新时间:2023-12-02 07:20:43 25 4
gpt4 key购买 nike

我添加了YouTube播放器,用于流式传输视频。当应用程序在后台运行时,视频会暂停,而在前台运行时会恢复视频。
但是在某些情况下,恢复状态会导致崩溃。
PFB的crashalytics屏幕截图:
enter image description here

它显示了在“恢复 Activity ”中找到的死对象。

这是我的Youtube播放器 Activity 代码:

   @Override
protected void onDestroy() {
Log.d("#ScreenONOFF","onDestroy" );
YouTubeShareClass.getInstance().showInterestialAd(this,"Video Player");

if (youTubePlayer != null) {
youTubePlayer.release();
youTubePlayer = null;
}
super.onDestroy();
if (mReceiver != null) {
unregisterReceiver(mReceiver);
}
}

@Override
public void onResume()
{
super.onResume();
if (youTubePlayer != null && videoID != null) {
youTubePlayer.loadVideo(videoID,currentPlayerTime);
youTubePlayer.play();
}
}

@Override
public void onPause()
{
super.onPause();
if (youTubePlayer != null) {
if(youTubePlayer.isPlaying()) {
currentPlayerTime = youTubePlayer.getCurrentTimeMillis();
youTubePlayer.pause();
}
}
}

@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
if (videoID != null) {
youTubePlayer = player;
if (youTubePlayer != null && mReceiver != null) {
if (wasRestored) {
player.play();
} else {
try {
player.loadVideo(videoID,0);
} catch (IllegalStateException e) {
youTubeView.initialize(YouTubeConstants.youtube_API_key, this);
}
}
mReceiver.player = player;
player.setFullscreen(true);
}
}
}

最佳答案

我有同样的问题。对我来说,重现错误很复杂,尽管我找到了该问题的Google跟踪器(https://issuetracker.google.com/issues/35172585)。
引用此答案(android.os.DeadObjectException at com.google.android.youtube.api.jar.client.RemoteEmbeddedPlayer.x)Google对于该错误有话要说:

public static final YouTubePlayer.ErrorReason UNEXPECTED_SERVICE_DISCONNECTION

Playback has been canceled and the player has been released due to an unexpected disconnection from the YouTube API service. Any further calls to this player instance will result in errors, a new player instance must be created to re-enable playback.


我无法100%验证此解决方案是否有效,因为我无法重现该错误,但这可能会有所帮助:
if(ytPlayer != null) {
try {
ytPlayer.loadVideo(videoId);
} catch (IllegalStateException e) {
initialize(API_KEY, this);
}
}

关于android - Android上的恢复 Activity 时YouTube播放器崩溃异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45876306/

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