1
프로그래밍 방식으로 여러 개의 YouTubePlayerView를 만들 수있는 활동이 있습니다. 다음은 각 YouTubePlayerView가 포함 된 클래스입니다.하나의 액티비티 내에 여러 YouTubePlayerView가 있습니다.
public class MyYouTubeView extends LinearLayout implements YouTubePlayer.OnInitializedListener {
private String mYouTubeVideoId;
private YouTubePlayerView mYouTubePlayerView;
public JournalYouTubeView(Activity context, String youTubeVideoId) {
super(context);
mYouTubeVideoId = youTubeVideoId;
String apiKey = context.getResources().getString(R.string.youtube_api_key);
mYouTubePlayerView = new YouTubePlayerView(context);
mYouTubePlayerView.setTag(mYouTubeVideoId);
mYouTubePlayerView.initialize(apiKey, this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
int margin = (int) ScreenUtils.dip2pixel(10, context);
params.leftMargin = margin;
params.rightMargin = margin;
addView(mYouTubePlayerView, params);
}
@Override
public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
final YouTubePlayer player,
boolean wasRestored) {
if (!wasRestored) {
player.cueVideo(mYouTubeVideoId);
}
}
}
불행하게도 이것은 내가 내 뷰 계층에 YouTubePlayerView를 여러 인스턴스를 가질 때 작동하지 않습니다. 샘플 API 앱에서는 여러 동영상을 처리 할 때 Fragments를 사용하는 것 같지만 앱을 대대적으로 다시 엔지니어링하지 않으면 사용할 수 없습니다. 어떤 도움을 많이 주셨습니다.