Android YouTube视频播放已停止,因为未经授权覆盖在播放器顶部
我对android youtube api有一些问题。当我第一次调用youtube intent时,我的代码似乎工作得很好,但是每当我将其称为 第二次我只能播放一秒钟。我通过一个文件中的简单按钮调用意图。衷心感谢所有帮助Android YouTube视频播放已停止,因为未经授权覆盖在播放器顶部,android,android-youtube-api,Android,Android Youtube Api,我对android youtube api有一些问题。当我第一次调用youtube intent时,我的代码似乎工作得很好,但是每当我将其称为 第二次我只能播放一秒钟。我通过一个文件中的简单按钮调用意图。衷心感谢所有帮助 ImageView btnplay_video = (ImageView) findViewById(R.id.button_video); btnplay_video.setOnClickListener(new OnClickListener() {
ImageView btnplay_video = (ImageView) findViewById(R.id.button_video);
btnplay_video.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Intent intent = new Intent(v.getContext(),
// ShimmerGraphandLogService.class);
// startActivityForResult(intent, 0);
Intent intent = new Intent(v.getContext(), youtube_player.class);
intent.putExtra("exercise",exercise_count );
startActivityForResult(intent, 0);
}
});
这是youtube布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
}
这是我收到的警告/错误
YouTube视频播放停止,因为未经授权的覆盖在播放器顶部。YouTubePlayerView不包含在它的祖先com.google.android.youtube.player.YouTubePlayerView{212125c5 V.E…..ID 0,0-0,0#7f0a0060应用程序中:ID/youtube_player_view}。祖先的边与YouTubePlayerView的边之间的距离是:左:0、上:0、右:0、下:0(这些都应该是正的)。找到解决方案了吗?
public class youtube_player extends YouTubeBaseActivity implements OnInitializedListener {
public String[] Exercises = { "Walking on the spot", "Side steps",
"V-step", "Running on the spot + arm movement", "Side jumps" };
public String[] Youtube_urls = {"FzZcCix_-3k","EIKh0AZGSEQ","pRgnFVAJZe8","R6hCksYs73M","Wx778vK_Lio"};
public String youtube_android_api_key = "AIzaSyCDfKgYduc4sGK9C1weGAIHzsM2LjtvM_M";
private YouTubePlayerView playerView;
private YouTubePlayer playa; //hollla
@Override
protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.youtube_player);
playerView = (YouTubePlayerView) findViewById(R.id.youtube_player_view);
playerView.initialize(youtube_android_api_key, this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.youtube_player, menu);
return true;
}
/**
* YouTubePlayerView init listeners
*/
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult error)
{
Toast.makeText(youtube_player.this,
"Oh dear, something has gone terribly wrong please try ejecting and re-inserting your diskette", Toast.LENGTH_LONG).show();
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer player, boolean wasRestored) {
playa = player;
playa.setPlaybackEventListener(new MHPlaybackEventListener());
playa.setPlayerStateChangeListener(new MHPlayerStateChangeListener());
playa.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);
int exercise = (int) this.getIntent().getExtras().get("exercise");
playa.cueVideo(Youtube_urls[exercise]);
//playa.play();
}
private class MHPlaybackEventListener implements PlaybackEventListener {
@Override
public void onBuffering(boolean arg0) {
//Toast.makeText(youtube_player.this, "onBuffering video...", Toast.LENGTH_SHORT).show();
}
@Override
public void onPaused() {
//Toast.makeText(youtube_player.this, "onPaused video...", Toast.LENGTH_SHORT).show();
}
@Override
public void onPlaying() {
//Toast.makeText(youtube_player.this, "onPlaying video...", Toast.LENGTH_SHORT).show();
}
@Override
public void onSeekTo(int arg0) {
//Toast.makeText(youtube_player.this, "onSeekTo video...", Toast.LENGTH_SHORT).show();
}
@Override
public void onStopped() {
//Toast.makeText(youtube_player.this, "onStopped video...", Toast.LENGTH_SHORT).show();
}
}
private class MHPlayerStateChangeListener implements PlayerStateChangeListener {
@Override
public void onAdStarted() {
//Toast.makeText(youtube_player.this, "onAdStarted video...", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(ErrorReason arg0) {
//Toast.makeText(youtube_player.this, "onError video...", Toast.LENGTH_SHORT).show();
}
@Override
public void onLoaded(String arg0) {
playa.play();
//pauseButton.setVisibility(View.VISIBLE);
}
@Override
public void onLoading() {
//Toast.makeText(youtube_player.this, "onLoading video...", Toast.LENGTH_SHORT).show();
}
@Override
public void onVideoEnded() {
//Toast.makeText(youtube_player.this, "onVideoEnded video...", Toast.LENGTH_SHORT).show();
}
@Override
public void onVideoStarted() {
//Toast.makeText(youtube_player.this, "onVideoStarted video...", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
this.finish();
View view = this.getWindow().getDecorView().findViewById(android.R.id.content);;
view.setVisibility(View.GONE);
}