我知道要使用
“&t = 0m25s”
用于将youtube视频设置为从开始算起的25秒。但是,有人可以帮助我使用 YouTubePlayerSupportFragment
设置相同功能吗这是我的代码
YouTubePlayerSupportFragment playerFragment = YouTubePlayerSupportFragment.newInstance();
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.fl_video, playerFragment).commit();
playerFragment.initialize(API_KEY, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
player.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
player.play();
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult error) {
// YouTube error
String errorMessage = error.toString();
Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_LONG).show();
Log.d("errorMessage:", errorMessage);
}
});
答案 0 :(得分:3)
我找到了解决此问题的方法。有一种叫做
的东西YouTubePlayerSupportFragment中的cueVideo()
函数。
player.cueVideo("QYw77aNGXnE", 92000);
注意:92000对应于92秒(1分32秒),因为该值需要以毫秒为单位。