Android Youtube Api更改视频ID按钮单击

时间:2014-04-15 09:36:44

标签: android youtube-api

我正在使用android youtube api.i成功创建youtube api project.i可以播放视频并跳过视频 现在我想将按钮点击中的视频ID更改为onInitializationSuccess方法? 我怎么能解决我的问题。我不知道如何在onInitializationSuccess方法中更改视频ID 这是我的来源。在我的代码中,VIDEO和VIDEO1是视频ID,我想在按钮点击中进行更改

public class MainActivity extends YouTubeBaseActivity implements
    YouTubePlayer.OnInitializedListener {

static private final String DEVELOPER_KEY = "***********";
private String VIDEO = "RkZkekS8NQU", VIDEO1 = "cQ-48rr6Wfo";
private Button b1, b2;;
private YouTubePlayer player1;
public int endTime = 8000;

 private PlayerStyle style;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
    b1 = (Button) findViewById(R.id.button1);
    b2 = (Button) findViewById(R.id.button2);

    youTubeView.initialize(DEVELOPER_KEY, this);
    youTubeView.setEnabled(false);
     style = PlayerStyle.CHROMELESS;
    b2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            int[] array = new int[] { 36000, 140000, 250000 };

            Random random = new Random();
            final int index = array[random.nextInt(array.length)];

            Log.e("randommmmmmmmmmmm", String.valueOf(index));

             player1.seekToMillis(index);
            //player1.loadVideo(VIDEO1, index);

        }
    });
    b1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            int[] array = new int[] { 36000, 140000, 250000 };

            Random random = new Random();
            final int index = array[random.nextInt(array.length)];

            Log.e("randommmmmmmmmmmm", String.valueOf(index));
            // player1.loadVideo(VIDEO, index);
            //player1.loadVideo(VIDEO, index);
             player1.seekToMillis(index);

        }
    });
}

@Override
public void onInitializationFailure(Provider provider,
        YouTubeInitializationResult error) {
    Toast.makeText(this, "Oh no! " + error.toString(), Toast.LENGTH_LONG)
            .show();
}

@Override
public void onInitializationSuccess(Provider provider,
        YouTubePlayer player, boolean wasRestored) {
    this.player1 = player;
     player1.setPlayerStyle(style);

    player1.loadVideo(VIDEO);



}

}

0 个答案:

没有答案