【问题标题】:YouTubePlayer(View) keeps pausing in landscapeYouTubePlayer(View) 一直在横向暂停
【发布时间】:2013-11-14 15:28:14
【问题描述】:
我正在构建一个包含 YouTubePlayerView 和 YouTubePlayer 的应用程序,它适用于纵向、全屏横向但不支持横向。按下播放后,它每秒都会暂停。缓冲区显示它在某些视频上已完全加载,但它一直在暂停。
我使用最新版本的 YouTube 应用在 Android 2.2.2 和 Android 4.1.2 上对其进行了测试。
这发生在所有玩家风格中。
提前致谢。
【问题讨论】:
标签:
android
youtube-api
android-youtube-api
【解决方案2】:
我也面临同样的问题。但我只是使用以下概念,它对我有用。
- 在您的活动布局 xml 中采用线性布局。
<LinearLayout android:id="@+id/ll_youtube_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="@dimen/_55sdp"
android:layout_marginStart="@dimen/_55sdp"
android:layout_marginRight="@dimen/_55sdp"
android:layout_marginEnd="@dimen/_55sdp"
android:orientation="vertical"
/>
- 采用将定义 youtube 播放器的布局 layout_youtube_video_view_detail.xml。
<com.google.android.youtube.player.YouTubePlayerView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/you_tube_player_view" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"/>
- 在 onCreate() 内的活动中,膨胀 youtube xml 并通过代码添加到您的布局中:
LinearLayout llYoutubePlayer = (LinearLayout)findViewById(R.id.ll_youtube_player);
youTubePlayerView = (YouTubePlayerView) getLayoutInflater().inflate(R.layout.layout_youtube_video_view_detail, null);
llYoutubePlayer.addView(youTubePlayerView);
youTubePlayerView = (YouTubePlayerView) findViewById(R.id.you_tube_player_view);
youTubePlayerView.initialize(AppConstants.YOU_TUBE_API_KEY, this);
- 请在您的 onInitializationSuccess 中传递视频 ID。
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
player.setPlayerStateChangeListener(playerStateChangeListener);
/** Start buffering **/
if (!wasRestored) {
player.loadVideo(videoId);
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
youTubePlayerView.refreshDrawableState();
}
}, AppConstants.DELAY_500);
}
我希望它会起作用。