无法使用YouTubeAndroidPlayer api提供起始值和结束值

无法使用YouTubeAndroidPlayer api提供起始值和结束值,android,youtube-api,Android,Youtube Api,我正在使用YouTubeAndroidPlayer api在我的应用程序中播放youtube视频。我想从中间开始视频,但无法找到youtube api中的(开始和结束)方法 https://www.youtube.com/v/BmOpD46eZoA?start=36&end=65 在YouTubeAndroidPlayer api中,我有一个如下的代码用于播放视频。我无法从视频的中间开始。我没有在player下找到任何方法来给出起始值和结束值 我寻找了很多解决方案,但没有找到任何运气。

我正在使用YouTubeAndroidPlayer api在我的应用程序中播放youtube视频。我想从中间开始视频,但无法找到youtube api中的(开始和结束)方法

https://www.youtube.com/v/BmOpD46eZoA?start=36&end=65
在YouTubeAndroidPlayer api中,我有一个如下的代码用于播放视频。我无法从视频的中间开始。我没有在player下找到任何方法来给出起始值和结束值

我寻找了很多解决方案,但没有找到任何运气。请建议

 @Override
 public void onInitializationSuccess(Provider provider, YouTubePlayer player,
   boolean wasRestored) {
  if (!wasRestored) {
//        player.cueVideo(VIDEO_ID);

        player.loadVideo(xyoajjlPt_o);

      }

使用带有
timeMillis
参数的方法:

player.loadVideo (String videoId, int timeMillis) 
就你而言:

player.loadVideo("xyoajjlPt_o", 36000); 
//this will start the video from 36th second
[编辑]

嗯,您可以使用处理程序来跟踪视频的当前运行时间。当以毫秒为单位的时间达到要停止视频的时间点时,只需调用
player.pause()
方法即可

以下是活动的完整代码:

public class MyActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{

    public static final String API_KEY = "YOUR_API_KEY_HERE";
    public static final String VIDEO_ID = "yeF_b8EQcK0";
    private static YouTubePlayer player;

    TextView text;

    //this is the end time in milliseconds (65th second)
    public int endTime = 65000; 


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_activity);
        text = (TextView) findViewById(R.id.text);
        YouTubePlayerView youTubePlayerView = (YouTubePlayerView)findViewById(R.id.youtubeplayerview);
        youTubePlayerView.initialize(API_KEY, this);
    }

    @Override
    public void onInitializationFailure(Provider provider,
            YouTubeInitializationResult result) {
        Toast.makeText(getApplicationContext(), 
                "onInitializationFailure()", 
                Toast.LENGTH_LONG).show();
    }

    @Override
    public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {

        MyActivity.player = player; //necessary to access inside Runnable 

        //start the video at 36th second
        player.loadVideo(VIDEO_ID, 36000);

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //For every 1 second, check the current time and endTime
                if(MyActivity.player.getCurrentTimeMillis() <= endTime) { 
                    text.setText("Video Playing at " + MyActivity.player.getCurrentTimeMillis());
                    handler.postDelayed(this, 1000);
                } else {
                    handler.removeCallbacks(this); //no longer required
                    text.setText(" Reached " + endTime);
                    MyActivity.player.pause(); //and Pause the video
                }
            }
        }, 1000);
    }
}
公共类MyActivity扩展YouTubeBaseActivity实现YouTubePlayer.OnInitializedListener{
public static final String API\u KEY=“YOUR\u API\u KEY\u HERE”;
公共静态最终字符串视频\u ID=“yeF\u b8EQcK0”;
私人静态YouTueplayer播放器;
文本查看文本;
//这是以毫秒为单位的结束时间(65秒)
公共int endTime=65000;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.my_活动);
text=(TextView)findViewById(R.id.text);
YouTubePlayerView YouTubePlayerView=(YouTubePlayerView)findViewById(R.id.YouTubePlayerView);
初始化(API_键,this);
}
@凌驾
public void onInitializationFailure(提供程序,
YouTube初始化结果(结果){
Toast.makeText(getApplicationContext(),
“onInitializationFailure()”,
Toast.LENGTH_LONG).show();
}
@凌驾
public void onInitializationSuccess(提供程序提供程序、YouTubePlayer播放器、布尔值已还原){
MyActivity.player=player;//访问Runnable内部所必需的
//在第36秒开始播放视频
player.loadVideo(VIDEO_ID,36000);
最终处理程序=新处理程序();
handler.postDelayed(新的Runnable(){
@凌驾
公开募捐{
//每1秒检查一次当前时间和结束时间

如果(MyActivity.player.getCurrentTimeMillis()可能与上述问题重复,请就上述问题提出建议?如何给出最终值和控件