我正在尝试使用Youtube Intents
以全屏模式播放视频我想要做的是我在Xml中有一个TubePlayerView如下面的代码
public class CallingIntent extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
public static final String develop_you_key = " i have my key";
YouTubePlayerView youTubeView;
TextView ID,Video_id,Video_name,duration,countView,published;
String ID1,Video_id1,Video_name1,duration1,countView1,published1;
private static final int RECOVERY_DIALOG_REQUEST = 1;
YouTubePlayer youTubePlayer;
MediaPlayer mPlayer;
Intent receInt;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.vid_play);
Intent in = getIntent();
// String st= in.getStringExtra("image");
ID1=in.getStringExtra("ID");
Video_id1=in.getStringExtra("video_id");
Video_name1=in.getStringExtra("video_name");
ID =(TextView) findViewById(R.id.textView1);
Video_id =(TextView) findViewById(R.id.textView2);
Video_name=(TextView)findViewById(R.id.textView3);
ID.setText(ID1);
Video_id.setText(Video_id1);
Video_name.setText(Video_name1);
youTubeView= (YouTubePlayerView) findViewById(R.id.videoView1);
youTubeView.initialize(develop_you_key,(YouTubePlayer.OnInitializedListener)this);
findViewById(R.id.videoView1).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = YouTubeIntents.createPlayVideoIntentWithOptions(getApplicationContext(), Video_id1, true, false);
startActivity(intent);
finish();
}
});;
mPlayer = new MediaPlayer();
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider player,
YouTubeInitializationResult errorReason) {
// TODO Auto-generated method stub
String errorMessage = errorReason.toString();
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
// TODO Auto-generated method stub
if(!wasRestored)player.cueVideo(Video_id1);
}
}
使用id videoView的youtubeplayer视图,当我点击它时我想播放关于新意图的视频使用youtube意图作为代码如下。
但问题是在实现onClick之后事件没有调用Intent
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"AnalysisScreen"]) {
AnalysisViewController *analysisViewController = segue.destinationViewController;
analysisViewController.currentQuiz = self.currentQuiz;
}
}
请观察onclickListener并告诉我有关初始化的成功如何直接播放视频使用Youtube意图" YouTubeIntents.createPlayVideoIntentWithOptions"
问题是我想加载视频并不想要缩略图而不是VideoView。
答案 0 :(得分:0)
经过大量修改后,我在xml文件中将com.google.android.youtube.player.YouTubePlayerView更改为com.google.android.youtube.player.YouTubeThumbnailView
并加载图片 `
<com.google.android.youtube.player.YouTubeThumbnailView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="2dp"
android:paddingTop="5dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>`
从youtube加载图片并以全屏模式播放视频 代码修改为
public class VideoDetailView extends YouTubeBaseActivity implements YouTubeThumbnailView.OnInitializedListener{
public static final String develop_you_key = "i have my key";
YouTubePlayerView youTubeView;
TextView ID,Video_id,Video_name,duration,countView,published;
String ID1,Video_id1,Video_name1,duration1,countView1,published1;
//YouTubePlayerView youtubeplayer =(YouTubePlayerView) findViewById(R.id.videoView1);
YouTubeThumbnailView YoutubeThumb ;
YouTubeThumbnailLoader youTubeThumbnailLoader;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.video_detail);
Intent in = getIntent();
// String st= in.getStringExtra("image");
ID1=in.getStringExtra("ID");
Video_id1=in.getStringExtra("video_id");
Video_name1=in.getStringExtra("video_name");
duration1=in.getStringExtra("duration");
countView1=in.getStringExtra("viewcount");
published1=in.getStringExtra("published");
// VideoView vv =(VideoView) findViewById(R.id.videoView1);
ID =(TextView) findViewById(R.id.textView1);
Video_id =(TextView) findViewById(R.id.textView2);
Video_name=(TextView)findViewById(R.id.textView3);
duration= (TextView)findViewById(R.id.textView4);
countView=(TextView)findViewById(R.id.textView5);
published=(TextView)findViewById(R.id.textView6);
ID.setText(ID1);
Video_id.setText(Video_id1);
Video_name.setText(Video_name1);
duration.setText(duration1);
countView.setText(countView1);
published.setText(published1);
YoutubeThumb= (YouTubeThumbnailView) findViewById(R.id.videoView1);
YoutubeThumb.initialize(develop_you_key,(YouTubeThumbnailView.OnInitializedListener)this);
YoutubeThumb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = YouTubeIntents.createPlayVideoIntentWithOptions(getApplicationContext(), Video_id1, true, false);
startActivity(intent);
}
});
}
@Override
public void onInitializationFailure(YouTubeThumbnailView thumbnail,
YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub
}
@Override
public void onInitializationSuccess(YouTubeThumbnailView thumbnail,
YouTubeThumbnailLoader imageLoader) {
// TODO Auto-generated method stub
youTubeThumbnailLoader = imageLoader;
imageLoader.setOnThumbnailLoadedListener(new OnThumbnailLoadedListener() {
@Override
public void onThumbnailLoaded(YouTubeThumbnailView arg0, String arg1) {
// TODO Auto-generated method stub
}
@Override
public void onThumbnailError(YouTubeThumbnailView arg0, ErrorReason arg1) {
// TODO Auto-generated method stub
}
});
youTubeThumbnailLoader.setVideo(Video_id1);
}
}