小编Rus*_*lGk的帖子

如何在我的 SupportFragment 中添加 YouTube 播放器?

我的 XML 代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    style="@style/Container.MainBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
        android:layout_alignParentTop="true"
        android:id="@+id/youtube_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

片段中的代码

public class VideoFragment extends YouTubePlayerSupportFragment implements YouTubePlayer.OnInitializedListener {

    static private final String DEVELOPER_KEY = "MyKey";
    static private final String VIDEO = "ToMpzhdUD1Q";
    static private final String VIDEO1 = "K77avo920Jc";
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View videoView = inflater.inflate(R.layout.video_fragment, container, false);
        getActivity().setTitle("Youtube");

        YouTubePlayerSupportFragment youTubePlayerSupportFragment = new YouTubePlayerSupportFragment();
        youTubePlayerSupportFragment.initialize(DEVELOPER_KEY, this);

        return videoView;
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer …
Run Code Online (Sandbox Code Playgroud)

youtube android fragment android-fragments

5
推荐指数
1
解决办法
1769
查看次数

标签 统计

android ×1

android-fragments ×1

fragment ×1

youtube ×1