播放video全屏

我正在尝试在我的应用中播放video。 它必须embedded。

我通过“在Android播放video文件”线程。

我可以使用VideoView播放我的video,如讨论中所述。 但是有一些问题。

  1. 我需要全屏video,如何将VideoView拉伸到全屏? 这也会延长video吗?

  2. 我根本不需要默认的播放/转发/停止button。 基本上我需要连续循环播放video。

我在这里尝试了MediaPlayer类,但它从来没有工作。 如果我的video文件在res / raw目录下,string格式应该是什么样的? 我真的不希望从SD卡播放的video文件。 它如何与应用程序捆绑在一起?

如果这两种方法中的任何一种都行得通,我会过得更好。

这是我的代码:

videoHolder = new VideoView(this); // videoHolder = (VideoView)findViewById(R.id.videoview); LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); videoHolder.setLayoutParams(params); videoHolder.setMediaController(new MediaController(this)); setContentView(videoHolder); // // //// I tested and found that it works fine for .wmv, .3gp and .mp4 //// videoHolder.setVideoURI(Uri.parse("file:///sdcard/video.3gp")); videoHolder.setVideoURI(Uri.parse("res/raw/demo.3gp")); videoHolder.requestFocus(); videoHolder.start(); 

奇怪的是,评论的url(sdcard)。 另一个不起作用。 我已经尝试了很多从“file:// res / raw / demo.3gp”到“demo”的组合。

什么是正确的string来访问该文件?

不需要为全屏模式播放video做任何编码

在包含videoview的xml上应用以下布局格式,肯定会以全屏模式播放video。 因为它正在运行我的。 :)希望它有帮助

  <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <VideoView android:id="@+id/myvideoview" android:layout_width="fill_parent" android:layout_alignParentRight="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:layout_height="fill_parent"> </VideoView> </RelativeLayout> 

另外添加mediacontroller也会给你控制器使用。

我已经解决了这个问题:

1.要取消继续/暂停button,请取出介质控制器。 对于循环的问题,把OnCompletionListener以便当video到达结束时,它再次启动:

 videoView.setOnCompletionListener( new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer mp) { videoView.start(); } }); 

2.要调整video大小,请在VideoView重写onMeasure()方法,如下所示:

 public class MyVideoView extends VideoView { public MyVideoView(Context context) { super(context); } @Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(480,800); } } 

我知道这个线程是几个星期的时间,但你不必复制video文件到SD卡只是为了播放它。 使用以下内容,但插入你的包名称而不是“com.yourcompany.yourproject”:

videoView.setVideoURI(Uri.parse("android.resource://com.yourcompay.yourproject/" + R.raw.yourvideoresource));

如果您想以全屏方式播放video,只需在Androidmanifest.xml文件中将这些代码添加到该video即将播放的活动中即可。 只需在android清单文件中添加这两行。

  android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:configChanges="orientation|screenSize" 

就像在我的androidmanifest.xml文件中添加的那样

  <activity android:name="com.appliconic.straminglivevideo.MainActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:configChanges="orientation|screenSize" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 

修改@ Javanator的回答了一下,这不会拉伸video:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <VideoView android:id="@+id/myvideoview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> </VideoView> </RelativeLayout> 

希望这可以帮助别人:)