2015-09-28 3 views
1

У меня проблема с просмотром плеера youtube в Android.У меня есть проблема с видимостью YouTubePlayer в android?

его ошибка ниже, когда его игра в какое-то время идет, а затем внезапно останавливается. И показать ошибку ниже.

YouTube video playback stopped because the player's view is not visible. 
The view com.android.internal.policy.impl.PhoneWindow$DecorView 
{36d050c2 I.E..... R.....ID 0,0-540,960} has visibility "INVISIBLE". 

Сообщите мне, что я могу сделать для этой ошибки. ??

My Activity code is here.

youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player); 
youTubePlayerView.initialize(GOOGLE_API_KEY, this); 


@Override 
public void onInitializationSuccess(YouTubePlayer.Provider provider, 
     YouTubePlayer youTubePlayer, boolean wasRestored) { 
    myYouTubePlayer = youTubePlayer; 
    // Change play style 
    youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT); 
    youTubePlayer 
      .addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI); 
    youTubePlayer.setPlayerStateChangeListener(this); 
    youTubePlayer.setPlaybackEventListener(this); 
    youTubePlayer.loadVideo("wKJ9KzGQq0w"); 
} 

@Override 
public void onInitializationFailure(YouTubePlayer.Provider provider, 
     YouTubeInitializationResult errorReason) { 
    if (errorReason.isUserRecoverableError()) { 
     errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show(); 
    } else { 
     String errorMessage = String.format(
       "There was an error initializing the YouTubePlayer (%1$s)", 
       errorReason.toString()); 
     Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show(); 
    } 
} 

Мой код файла XML находится здесь.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/rl_FullScreen" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#000" > 

<com.google.android.youtube.player.YouTubePlayerView 
    android:id="@+id/youtube_player" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/rl_CurrentVideoDetails" 
    android:layout_below="@+id/rl_Heading" 
    android:layout_toStartOf="@+id/rl_ChannelChange" 
    android:background="#000" /> 

<RelativeLayout 
    android:id="@+id/rl_Heading" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" > 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="12dp" 
     android:contentDescription="@null" 
     android:padding="8dp" /> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/rl_ChannelChange" 
    android:layout_width="50dp" 
    android:layout_height="match_parent" 
    android:layout_alignParentEnd="true" 
    android:background="@color/transparent_background_black" 
    android:gravity="center_horizontal" > 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_above="@+id/ll_ChNo" 
     android:layout_marginBottom="16dp" 
     android:contentDescription="@null" 
     android:padding="8dp" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:contentDescription="@null" 
      android:gravity="center" 
      android:padding="4dp" 
      android:text="Ch." 
      android:textSize="16sp" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:contentDescription="@null" 
      android:gravity="center" 
      android:padding="4dp" 
      android:text="123" 
      android:textSize="16sp" /> 
    </LinearLayout> 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_below="@+id/ll_ChNo" 
     android:layout_marginTop="16dp" 
     android:contentDescription="@null" 
     android:padding="8dp"/> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/rl_CurrentVideoDetails" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerVertical="true" 
    android:background="@color/transparent_background_black" 
    android:paddingStart="12dp" > 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="6dp" 
     android:singleLine="true" 
     android:textStyle="bold" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tv_CurrentVideoName" 
     android:orientation="horizontal" 
     android:padding="6dp" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="marquee" 
      android:fadingEdge="horizontal" 
      android:marqueeRepeatLimit="marquee_forever" 
      android:singleLine="true" 
      android:textAllCaps="true" 
      android:textStyle="bold" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="| Ch. " 
      android:textStyle="bold" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="4dp" 
      android:singleLine="true" 
      android:textAllCaps="true" /> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/iv_NormalScreen" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentEnd="true" 
     android:layout_centerVertical="true" 
     android:contentDescription="@null" 
     android:padding="10dp" /> 
</RelativeLayout> 
+0

попытаться дать некоторые фиксированные конкретные значения для высоты и ширины YOUTUBE игрока, увидеть, если он работает. –

+0

Нет его не работает до сих пор выпуск –

+0

используйте последнюю версию youtube api, которую можно найти на своем официальном сайте, а также запустите приложение в обновленном приложении Youtube. –

ответ

1

У меня была такая же проблема в моем приложении прошлой ночью, и в итоге я нашел решение (по крайней мере для меня). Похоже, в моем приложении всегда была проблема, я случайно несколько раз запускал одно и то же намерение для своего YoutubePlayerActivity.

Раньше это не замечалось мной, однако последнее обновление Youtube должно было увеличить ограничение или изменить способ его работы, поскольку я получил эту ошибку.

Я прошел через свой код и обнаружил, что когда я добавляю фрагменты, он повторно вызывает onCreateView каждого фрагмента. Значение для всех трех фрагментов добавлено, я в конечном итоге назвал намерение три раза.

Надеюсь, это поможет.

+0

, так что вы имеете в виду, что вы должны проверить, что я напомню, что это действие? –

+0

хорошее наблюдение. Это очень помогло. – Keyul

0

Воспроизведение видео на YouTube остановлено, потому что вид игрока не отображается .

Ничто не должно перекрывать YouTubePlayerView (в соответствии с политикой компании Google). Это означает, что вам нужно учитывать z-индекс и/или перекрытие всех представлений в вашей иерархии.

В вашем случае, порядок элементов в файлах XML определяет Z-индекс и есть match_parent макет, который перекрывает YouTubePlayerView: вам нужно принести YouTubePlayerView на фронт, просто переместить его в качестве последнего пункт в макете:

<RelativeLayout 
    android:id="@+id/rl_Heading" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" > 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="12dp" 
     android:contentDescription="@null" 
     android:padding="8dp" /> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/rl_ChannelChange" 
    android:layout_width="50dp" 
    android:layout_height="match_parent" 
    android:layout_alignParentEnd="true" 
    android:background="@color/transparent_background_black" 
    android:gravity="center_horizontal" > 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_above="@+id/ll_ChNo" 
     android:layout_marginBottom="16dp" 
     android:contentDescription="@null" 
     android:padding="8dp" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:contentDescription="@null" 
      android:gravity="center" 
      android:padding="4dp" 
      android:text="Ch." 
      android:textSize="16sp" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:contentDescription="@null" 
      android:gravity="center" 
      android:padding="4dp" 
      android:text="123" 
      android:textSize="16sp" /> 
    </LinearLayout> 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_below="@+id/ll_ChNo" 
     android:layout_marginTop="16dp" 
     android:contentDescription="@null" 
     android:padding="8dp"/> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/rl_CurrentVideoDetails" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerVertical="true" 
    android:background="@color/transparent_background_black" 
    android:paddingStart="12dp" > 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="6dp" 
     android:singleLine="true" 
     android:textStyle="bold" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tv_CurrentVideoName" 
     android:orientation="horizontal" 
     android:padding="6dp" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="marquee" 
      android:fadingEdge="horizontal" 
      android:marqueeRepeatLimit="marquee_forever" 
      android:singleLine="true" 
      android:textAllCaps="true" 
      android:textStyle="bold" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="| Ch. " 
      android:textStyle="bold" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="4dp" 
      android:singleLine="true" 
      android:textAllCaps="true" /> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/iv_NormalScreen" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentEnd="true" 
     android:layout_centerVertical="true" 
     android:contentDescription="@null" 
     android:padding="10dp" /> 
</RelativeLayout> 

<com.google.android.youtube.player.YouTubePlayerView 
    android:id="@+id/youtube_player" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/rl_CurrentVideoDetails" 
    android:layout_below="@+id/rl_Heading" 
    android:layout_toStartOf="@+id/rl_ChannelChange" 
    android:background="#000" /> 

1

вы можете проверить, если ваш Youtube App имеет б обновление een в сентябре или позднее? Кажется, есть ошибка в Youtube App, что вызывает эту ошибку отдалить при использовании Youtube API:

https://code.google.com/p/gdata-issues/issues/detail?id=7586

Вы можете проверить, если эта ошибка вызвана Youtube App легко, удаление обновлений Youtube App и тестирования ваших приложение. Вы можете удалить обновления этого приложения, выбрав «Настройки»> «Основные»> «Приложения»> «Youtube» и нажмите кнопку «Удалить обновления».

Для меня это было причиной того, что мое видео YouTube YouTube не работает. Когда я удаляю обновления, мое приложение работает, когда я переустанавливаю обновления, а также снова крашу приложение.Так что, я думаю, что единственное решение ждать нового обновления :(

Надеюсь, это не помогает!

+0

Я уже там знаю, что .. я тоже там пишу –

Смежные вопросы