1

AndroidでYoutubeAndroidApiを使用する場合、ビデオアプリケーションでフラグメントを使用するにはどうすればよいですか?

このコードを参照して、私に提案してください...事前にあなたより..

MainActivity.java

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class Main extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Main" >


    <fragment 
        android:id="@+id/screen1"
        android:name="com.youtubedemofragment.screen1_fragment"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        tools:layout="@layout/screen1_fragment"
        />


</RelativeLayout>

screen1_fragment.java

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.OnInitializedListener;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerFragment;
import com.google.android.youtube.player.YouTubePlayerView;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class screen1_fragment extends YouTubePlayerFragment implements OnInitializedListener {


    private YouTubePlayer yplayer;
    private static final String YoutubeDeveloperKey = "AIzaSyBGlL6WYUIH7114uwwHzWqVmt0m609f4v8";
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.screen1_fragment, container,false);

        YouTubePlayerView screen1 = (YouTubePlayerView) view.findViewById(R.id.screen1);

        screen1.initialize(YoutubeDeveloperKey, this);


        return view;
    }
    @Override
    public void onInitializationFailure(Provider arg0,
            YouTubeInitializationResult arg1) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1,
            boolean arg2) {
        // TODO Auto-generated method stub

        arg1.cueVideo("EKXMK8SyUFo");   

    }

}

screen1_fragment.xml

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



    <com.google.android.youtube.player.YouTubePlayerView            
            android:id="@+id/screen1"
            android:layout_width="145sp"
            android:layout_height="145sp"                                 
        />

</LinearLayout>
4

0 に答える 0