I am really struggling with using the `YouTubePlayerFragment` in my 
application. My implementation looks like this:

    private void loadYouTubeVideo(final YouTubeViewHolder h, final Content 
content) {
    final YouTubePlayerFragment youTubePlayerFragment = 
YouTubePlayerFragment.newInstance();
    FragmentTransaction transaction = ((DetailActivity) 
getContext()).getFragmentManager().beginTransaction();
    transaction.add(R.id.fl_youtube, youTubePlayerFragment).commit();
    final ViewTreeObserver observer = h.mRlYouTube.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new 
ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
    youTubePlayerFragment.initialize(YOUTUBE_PLAYER_API_KEY, new 
YouTubePlayer.OnInitializedListener() {
    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, 
YouTubePlayer youTubePlayer, boolean wasRestored) {
    if(!wasRestored) {
              
 youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
    youTubePlayer.loadVideo(content.getVideoId());
    }
    }
    
    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider, 
YouTubeInitializationResult youTubeInitializationResult) {
    Log.e(getClass().getSimpleName(), "Error initializing YouTube Video 
with id ");
    FragmentTransaction transaction = ((DetailActivity) 
getContext()).getFragmentManager().beginTransaction();
    transaction.remove(youTubePlayerFragment);
    }
    });
    }
    });
    }

The initialization is no problem, as a YouTubePlayer is displayed and the 
video is loaded. But it immediately stops after one second with the 
following message:

    "YouTube video playback stopped due to the player's view being too 
small. The YouTubePlayerView is 0dp wide (minimum is 200dp) and 0dp high 
(minimum is 110dp)."

This is the XML layout with the `FrameLayout`, to which I add the 
`YouTubePlayerFragment` in the code above:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android";
        android:id="@+id/fl_youtube"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minWidth="200dp"
        android:minHeight="110dp"
        android:layout_marginBottom="5dp"
        >
    
    </FrameLayout>

I have no idea why the YouTubePlayer pretends to have width and height 0. 
When I log the size of the FrameLayout, its height is 607 and its width is 
1080 px. Any ideas how to solve this problem?

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/d1fb0f12-8803-40d3-842e-08c4b52c8f52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to