您好在YouTubeAndroidPlayerAPI中遇到问题,这是我面临的错误
W/YouTubeAndroidPlayerAPI: Forcefully created overlay:acqm@cada64
helper:Lazy@241a4cd view:null status: ....... {...}
注意 - 如果用户输入FirstActivity
视频工作正常,我有两个活动课程。如果用户在SecondActivity中将活动从FirstActivity
更改为SecondActivity
,视频也能正常工作,如果用户使用系统返回按钮导航到FirstActivity视频,则不会连续播放加载但视频无法播放。(添加图片供参考)< / p>
如果用户点击这样的按钮,则加载相同的活动(在我的情况下,FirstActivity和SecondActivity是相同的,只是为了不明原因解释了两个活动)
Intent intent = new Intent(YoutubeVideoPlay.this, YoutubeVideoPlay.class);
startActivity(intent);
以下是我正在使用的代码示例
FirstActivity.java
public class FirstActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
public static final String DEVELOPER_KEY = "xxxxxxxxxxxxxxxxxxx";
private static final int RECOVERY_DIALOG_REQUEST = 1;
private String url = "xxxxxxxxxxxxxxxxxxxx";
private String VIDEO_ID;
private YouTubePlayerFragment myYouTubePlayerFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_youtube);
myYouTubePlayerFragment = (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.youtubeplayerfragment);
myYouTubePlayerFragment.initialize(DEVELOPER_KEY, this);
VIDEO_ID = getYoutubeVideoId(url);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FirstActivity .this, FirstActivity .class);
startActivity(intent);
}
});
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult errorReason) {
if (errorReason.isUserRecoverableError()) {
errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
} else {
String errorMessage = String.format("There was an error initializing the YouTubePlayer (%1$s)",
errorReason.toString());
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
}
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
player.cueVideo(VIDEO_ID);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RECOVERY_DIALOG_REQUEST) {
// Retry initialization if user performed a recovery action
getYouTubePlayerProvider().initialize(DEVELOPER_KEY, this);
}
}
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerView) findViewById(R.id.youtubeplayerfragment);
}
public static String getYoutubeVideoId(String youtubeUrl) {
String video_id = "";
if (youtubeUrl != null && youtubeUrl.trim().length() > 0 && youtubeUrl.startsWith("http")) {
String expression = "^.*((youtu.be" + "\\/)" + "|(v\\/)|(\\/u\\/w\\/)|(embed\\/)|(watch\\?))\\??v?=?([^#\\&\\?]*).*"; // var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
CharSequence input = youtubeUrl;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(input);
if (matcher.matches()) {
String groupIndex1 = matcher.group(7);
if (groupIndex1 != null && groupIndex1.length() == 11)
video_id = groupIndex1;
}
}
return video_id;
}
}
答案 0 :(得分:0)
是的,youtube主要单一全球玩家如果你开始新玩家,之前的玩家将自动释放。
因此,您需要在恢复活动时重新启动youtube播放器