how to use YouTubeBaseActivity in Fragment ,android

时间:2015-06-08 11:56:57

标签: android fragment

I useing the tabhost, I hope to use YouTubeBaseActivity in fragment what can I do?

public class yutubemain extends YouTubeBaseActivity implements
    YouTubePlayer.OnInitializedListener {

    private YouTubePlayerView ytpv;
    private YouTubePlayer ytp;
    final String serverKey="AIzaSyBrNphq0HsQvQ5Rx4-Kenff-FhumNVMbnY"; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ytpv = (YouTubePlayerView) findViewById(R.id.youtubeplayer);
        ytpv.initialize(serverKey, this);

    }

    @Override
    public void onInitializationFailure(Provider arg0,
        YouTubeInitializationResult arg1) {
        Toast.makeText(this, "Initialization Fail", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onInitializationSuccess(Provider provider,
                                        YouTubePlayer player, boolean wasrestored) {
        ytp = player;

        Intent gt =getIntent();
        ytp.loadVideo(gt.getStringExtra("id"));
    }
}

this code change in fragment...

1 个答案:

答案 0 :(得分:0)

如果您仅在单个support.v4.app.Fragment中而不是YouTubePlayerSupportFragment中播放YouTube视频,请使用YouTubeBaseActivity