通过启动youtube播放youtube视频文件:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(text2.getText().toString()));
intent.setPackage("com.google.android.youtube");
mActivity.startActivity(intent);
我有什么办法restrict user to see videos only in landscape mode
。我dont want to show the comments and relatedvideos
等等。
这可能。
由于
答案 0 :(得分:3)
解决方案::: D
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=VIDEOID"));
intent.putExtra("force_fullscreen",true);
startActivity(intent);
答案 1 :(得分:1)
不,这是不可能的。您无法控制Youtube应用程序......事实上,您无法确定该应用程序是否会安装。
答案 2 :(得分:1)
不......你基本上是在启动外部应用程序来显示该视频,一旦你这样做,你就不再拥有控制权。
但是,如果你有视频链接(不是youtube链接),你可以尝试显示媒体查看器并自己流式传输视频:
public class VideoPlayerActivity extends Activity {
private static final String TAG = "VideoPlayerActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
if(getIntent().getExtras() == null || !getIntent().getExtras().containsKey("uri")) {
Log.w(TAG, "URI not found!");
finish();
return;
}
super.onCreate(savedInstanceState);
setContentView(R.layout.video_player);
final ProgressDialog progressDialog = ProgressDialog.show(this, "Preloading video...", "Press Back to cancel");
progressDialog.show();
progressDialog.setCancelable(true);
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog1) {
finish();
}
});
final VideoView view = (VideoView)findViewById(R.id.videoPlayer);
view.setMediaController(new MediaController(this));
view.setVideoURI(Uri.parse(getIntent().getExtras().getString("uri")));
view.requestFocus();
view.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
view.start();
}
});
}
}
和XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView android:id="@+id/videoPlayer"
android:layout_width="match_parent" android:layout_height="match_parent" />
</FrameLayout>