마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

유튜브 안드로이드 API 데모에 대한 질문

0 추천

앱에 유튜브 동영상을 추가하고 싶어서 

구글에서 유튜브 안드로이드 플레이어 API를 다운받았습니다.

https://developers.google.com/youtube/android/player/downloads/

소스 파일 import하고 유튜브 앱 설치해서 정상적으로 실행은 되는데요.

PlayerViewDemoActivity.java, playerview_demo.xml 에서
동영상을 2개 이상 추가하려면 어떻게 하는지 모르겠네요.

/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.examples.youtubeapidemo;

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;

import android.os.Bundle;

/**
 * A simple YouTube Android API demo application which shows how to create a simple application that
 * displays a YouTube Video in a {@link YouTubePlayerView}.
 * <p>
 * Note, to use a {@link YouTubePlayerView}, your activity must extend {@link YouTubeBaseActivity}.
 */
public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.playerview_demo);

    YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
    youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
  }

  @Override
  public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
      boolean wasRestored) {
    if (!wasRestored) {
      player.cueVideo("wKJ9KzGQq0w");
    }
  }

  @Override
  protected YouTubePlayer.Provider getYouTubePlayerProvider() {
    return (YouTubePlayerView) findViewById(R.id.youtube_view);
  }

}
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright 2012 Google Inc. All Rights Reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

  <TextView
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:textAppearance="@android:style/TextAppearance.Small"
      android:gravity="center"
      android:text="@string/playerview_text"/>

  <com.google.android.youtube.player.YouTubePlayerView
      android:id="@+id/youtube_view"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>

</LinearLayout>

 

smilekiko (170 포인트) 님이 2014년 12월 11일 질문

2개의 답변

0 추천
 
채택된 답변
유투브 재생파일 리스트를 추가하고 싶으신 거라면

비디오 ID 값이 저장된 ArrayList를 만들어서

player.loadVideos(mPlayList);

이렇게 날리시면 됩니다.

그리고 영상이 끝났을때 호출되는 콜백메서드를 오버라이딩 하여

player.next()로 다음영상으로 넘기시면 됩니다.

유투브  플레이어 SDK는 생각보다 잘만들어져있더군여..
갸아악 (21,260 포인트) 님이 2014년 12월 11일 답변
smilekiko님이 2014년 12월 11일 채택됨
제 질문의 요점은 YouTubePlayerView를 2개 이상 추가할 수 있나는 거였는데 ^.^;;

아무튼 두분 답변 감사합니다.
0 추천
한 화면에 2개 이상 재생하는 것은 안 될 겁니다.
익명사용자 님이 2014년 12월 11일 답변
죄송하지만 안되는 이유라도 있는지요? -_-;;

다른데 찾아봤는데 안된다고 하네요..

http://stackoverflow.com/questions/15547056/mutiple-youtubeplayerviews-within-one-actvity
...