我使用以下活动从我的应用程序启动YouTube视频。 当活动启动时,将播放YouTube视频。但是当我改变屏幕的方向时,视频不会恢复,而是从一开始就开始。 这里有什么问题?YouTubePlayerView在屏幕方向更改上重新加载视频
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);
}
}
如果您旋转屏幕,是重新创建你的活动。也许你必须听'OnConfigurationChanged'事件,并检查视频是否正在播放。如果是的话,保存当前时间码和初始化视频与保存的时间码...至少我会检查(这是猜测在黑暗中) – longilong