Java 有没有办法恢复YouTube API视频?
我正在使用YouTube API为Android编写一个简单的应用程序——我想达到这样一种状态:我将自动恢复我在应用程序中选择的每个视频/直播流。当我初始化一个应用程序时,我能够设置自动播放。当前的问题是,当我试图像下面的代码那样执行时,它并没有执行我想要的操作(每次当我将该应用程序转到后台并继续时,它都会显示播放按钮)Java 有没有办法恢复YouTube API视频?,java,android,youtube,Java,Android,Youtube,我正在使用YouTube API为Android编写一个简单的应用程序——我想达到这样一种状态:我将自动恢复我在应用程序中选择的每个视频/直播流。当我初始化一个应用程序时,我能够设置自动播放。当前的问题是,当我试图像下面的代码那样执行时,它并没有执行我想要的操作(每次当我将该应用程序转到后台并继续时,它都会显示播放按钮) 提前感谢您的善意帮助和建议 我为您提供了解决方案: 我有完全相同的问题,在跳进官方提供的例子后,我发现,令我沮丧的是,他们有完全相同的问题。外部控制似乎无法以任何重要方式与玩家
提前感谢您的善意帮助和建议 我为您提供了解决方案: 我有完全相同的问题,在跳进官方提供的例子后,我发现,令我沮丧的是,他们有完全相同的问题。外部控制似乎无法以任何重要方式与玩家互动。更不用说找一个新的YoutubePlayer往往是有问题的。然而,通过测试和尝试不同的东西,我成功地发现了一些东西: 即使将静态引用保存到YoutubePlayer,此引用也无法以任何方式更改播放器。但您仍然可以检索视频暂停的位置。因此,我下一个合乎逻辑的步骤是尝试:
Integer myMILLIS = yplayer.getCurrentTimeMillis();
Integer myMILLIS = yplayer.getCurrentTimeMillis();
// Reload the SAME VIDEO again (yplayer is the YoutubePlayer)
yplayer.cueVideo(mVideoURL);
// Get the position you saved back
yplayer.seekToMillis(myMILLIS);
// Start Playing the video from that position again
yplayer.play();
yplayer.cueVideo(mVideoURL);
之后立即调用任何其他内容都将失败。因此,这可能是一个奇怪的解决方案,但它确实非常有效:
Integer myMILLIS = yplayer.getCurrentTimeMillis();
Integer myMILLIS = yplayer.getCurrentTimeMillis();
// Reload the SAME VIDEO again (yplayer is the YoutubePlayer)
yplayer.cueVideo(mVideoURL);
// The next pause is here to allow the video to load
try
{
Thread.sleep(1000);
} catch (InterruptedException e)
{
// Do something here if you need to
}
// Get the position you saved back
yplayer.seekToMillis(myMILLIS);
// Start Playing the video from that position again
yplayer.play();