在视频观看时,YouTube视频停止工作

时间:2017-05-21 22:48:41

标签: android video youtube

我正在使用android studio在android应用程序中工作。 你在视频视频中播放视频,但是当开始播放视频时它只播放视频的一小部分然后停止工作,我需要按播放按钮播放智能部分然后再次停止工作等等。 视频怎样才能结束? 我的代码:     YouTubePlayerFragment myYoutubeFragment;

Button button;
YouTubePlayer.OnInitializedListener onInitializedListener;*/


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_song);

    myYoutubeFragment=(YouTubePlayerFragment)getFragmentManager().findFragmentById(R.id.youtubePlayerFragment);
    myYoutubeFragment.initialize(API_KEY,this);

}
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult errorReason)
{
    if(errorReason.isUserRecoverableError())
    {
        errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
    }
    else
        {
            String errorMessage= String.format("Error in youtube",errorReason.toString());
            Toast.makeText(this, errorMessage,Toast.LENGTH_LONG).show();
        }
}
public void onInitializationSuccess(YouTubePlayer.Provider provider,YouTubePlayer player,boolean wasRestored)
{
    //start buffering
    if(!wasRestored)
    {
        player.cuePlaylist(PLAYLIST_ID);

    }

}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if(requestCode == RECOVERY_DIALOG_REQUEST )
    {
        //retry initialization if user performed a recovery action
        getYouTubePlayerProvider().initialize(API_KEY,this);
    }


}
protected YouTubePlayer.Provider getYouTubePlayerProvider()
{
    return (YouTubePlayerView)findViewById(R.id.youtubePlayerFragment);
}

public void onResume()
{
    super.onResume();
    myYoutubeFragment.onResume();
}

@Override
public void onPause()
{
    super.onPause();
    myYoutubeFragment.onPause();
}

0 个答案:

没有答案