【问题标题】: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


    【解决方案1】:

    确保 YoutubePlayer 视图的大小至少为 200x110 dp,如 Youtube API documentation 中所述。听起来它在横向模式下不符合这些要求。

    【讨论】:

    • 谢谢,这确实是问题所在,播放器在横屏时屏幕太大了
    【解决方案2】:

    我也面临同样的问题。但我只是使用以下概念,它对我有用。

    1. 在您的活动布局 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"
        />
    
    1. 采用将定义 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"/>
    
    1. 在 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);

    1. 请在您的 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); }

    我希望它会起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-06
      • 2018-02-15
      • 2015-04-26
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      相关资源
      最近更新 更多