2017-07-03 14 views
0

YouTubePlayerViewとYouTubePlayerFragmentの両方に非常に奇妙な問題があります。一部の端末でYouTubePlayerが1秒後に一時停止する

私のアプリは目覚まし時計であり、ユーザーは自分のアラームとしてYouTube動画を設定できます。ここで

は、アラート、フラグメントxmlです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/black"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/standard_button_size" 
     android:gravity="center_vertical"> 

     <TextView 
      android:id="@+id/tvSep" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginEnd="@dimen/activity_horizontal_margin" 
      android:layout_marginStart="@dimen/activity_horizontal_margin" 
      android:text="-" 
      android:textColor="@color/white_secondary_text" 
      android:textSize="@dimen/title_bold" /> 


     <TextView 
      android:id="@+id/tvNotificationHourYoutube" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentTop="true" 
      android:layout_toStartOf="@id/tvSep" 
      android:gravity="end" 
      android:text="7:00" 
      android:textColor="@color/white_secondary_text" 
      android:textSize="@dimen/title_bold" /> 

     <TextView 
      android:id="@+id/tvAlarmLabelYoutube" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_toEndOf="@id/tvSep" 
      android:gravity="center" 
      android:maxLines="1" 
      android:text="Wake up" 
      android:textColor="@color/white_secondary_text" 
      android:textSize="@dimen/title_bold" /> 

    </RelativeLayout> 

    <fragment 
     android:name="com.google.android.youtube.player.YouTubePlayerFragment" 
     android:id="@+id/ypvAlert" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:layout_marginBottom="@dimen/half_activity_vertical_margin" 
     android:layout_marginTop="@dimen/half_activity_vertical_margin" 
     android:minWidth="200dp" 
     android:minHeight="110dp"/> 

    <LinearLayout 
     android:id="@+id/llYoutubeButtons" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <android.support.v7.widget.AppCompatButton 
      android:id="@+id/btnStopAlarmBigYoutube" 
      android:layout_width="0dp" 
      android:layout_height="@dimen/standard_button_size" 
      android:layout_weight="1" 
      android:backgroundTint="@color/dark_primary_accent" 
      android:text="@string/stop_alarm" 
      android:textColor="?android:colorBackground" 
      android:textSize="@dimen/title_bold" 
      android:visibility="visible" /> 

     <Button 
      android:id="@+id/btnSnoozeYoutube" 
      android:layout_width="0dp" 
      android:layout_height="@dimen/standard_button_size" 
      android:layout_weight="1" 
      android:text="@string/snooze" 
      android:textSize="@dimen/title_bold" /> 

    </LinearLayout> 


</LinearLayout>  

そして、これはフラグメントが含まれているアクティビティのレイアウトxmlファイルです:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/fragmentContainer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

私は2台のスマートフォン(ネクサス5にアラームをテストそして1つの錠剤(Asus)上で。

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

事がネクサス5のビデオはほとんど常にある1秒後に停止していることである:それは使用してyoutuebアラームがある場合は、最初に私は景観上にあるアプリを強制しようとしました。私は今から2分のアラームを設定すると、試行の50%でOKを再生し、明日の朝にアラームを設定した場合、常に1秒後に停止します。 Huaweiでは、ほとんど常にOK、タブレットでは50/50です。

YouTube video playback stopped due to unauthorized overlay on top of player. 
The YouTubePlayerView is not contained inside its ancestor 
android.widget.FrameLayout{89c240f V........ ......I. 0,0-0,0}. The 
distances between the ancestor's edges and that of the YouTubePlayerView is: 
left: 0, top: 0, right: 0, bottom: 0 (these should all be positive). 

私はアラーム警告フラグメント上の任意でframeLayoutを持っていないが、私は私がでframeLayout置き換えフラグメントを含む活動XMLファイルにでframeLayoutを持っている:ビデオが停止したとき これは私が得るメッセージです

<?xml version="1.0" encoding="utf-8"?> 
<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/articles_list" 
android:name="com.sux.alarmclock.AlarmNotificationFragment" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:layout="@layout/fragment_alarm_alert_material_youtube" /> 

しかし、私は今でも、XMLのいずれかのでframeLayoutが存在しない場合でも、同じエラーメッセージが表示されます。断片と、xmlファイルは次のようになりそう。アプリでインタースティシャル広告が表示されるため、広告はキャンセルされましたが、エラーは引き続き発生します。

私は、風景ではなく肖像画にアクティビティを設定しようとしましたが、今はネクサスや花輪で作業していますが、ほとんどの場合、1秒後にほとんどタブレットで止まります。

アクティビティ内にYouTubePlayerFragmentを含めると、またはYouTubeBaseActivityを延長すると、アクティビティを開始するたびに、アクティビティのインスタンスが2つ追加されます。インテントまたは起動モード(私はそれが問題と関係があるかどうかわからない)

私はRTSPリンクを使ってWebViewでYouTubeを再生できますが、このプロジェクトを使用する必要があります: https://github.com/HaarigerHarald/android-youtubeExtractor

そして、開発者は、彼らがYotubeのポリシーに不慣れなバックドアを通してRTSPのURLを抽出していると言ってくれました。

YouTubeプレーヤーがすべてのデバイスで常に動作するようにします。誰にもアイデアはありますか?

答えて

0

documentationから、ビデオ再生中は、Viewの最小サイズは200x110 dpです。 viewを小さくすると、動画の再生が自動的に停止します。また、動画の再生中に他のビューとオーバーレイすることはできません。役立つかもしれない

追加参照:

希望します。

+0

xmlファイルでは、最小幅と高さがすでに200 * 110dpに設定されていて、YouTubeプレーヤーにオーバーレイされていないことがわかります。また、パディングもありません。 – SUXA

0

これらは、この問題の可能性のある問題です。

USER_DECLINED_RESTRICTED_CONTENT小さすぎるYouTubeのビュー - - 制限されたコンテンツに

BLOCKED_FOR_APPを再生しようとユーチューブビュー

PLAYER_VIEW_TOO_SMALLと重複する他のビュー - あなたの問題

UNAUTHORIZED_OVERLAYであるかを調べるためにlogcatを確認してください - 特定の動画がアプリのためにブロックされています。

問題が発生したときは、UNAUTHORIZED_OVERLAYが原因でした。

<RelativeLayout 
     android:id="@+id/parent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <ImageView 
      android:id="@+id/scImage" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:visibility="gone"/> 
     <FrameLayout 
      andriod:id"@+id/youtube_parent 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 
</RelativeLayout> 

画像ビューは、YouTubeプレーヤーを持っていたframelayout以下でした。私はそれを上に移動しました(最終的な固定レイアウトはの上の例です)、それが機能し始めました(私はZindexを設定してみました。