且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

播放视频全屏播放

更新时间:2023-12-06 14:26:34

不需要做任何编码播放视频全屏模式

应用下面的布局格式在包含videoview将肯定会以全屏模式播放视频的XML。因为它是运行矿。 :)希望它可以帮助

 < XML版本=1.0编码=UTF-8&GT?;
 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
           机器人:layout_width =FILL_PARENT
           机器人:layout_height =FILL_PARENT>
   < VideoView机器人:ID =@ + ID / myvideoview
             机器人:layout_width =FILL_PARENT
             机器人:layout_alignParentRight =真
             机器人:layout_alignParentLeft =真
             机器人:layout_alignParentTop =真
             机器人:layout_alignParentBottom =真
             机器人:layout_height =FILL_PARENT>
    < / VideoView>
 < / RelativeLayout的>
 

另外加入的MediaController也会给你使用的控制器。

I am trying to play a video in my app. It has to be embedded.

I went through the "Play Video Files in Android" thread.

I am able to play my video using VideoView as mentioned in this discussion. But there are a few problems.

  1. I need full screen video, how do I stretch VideoView to full screen? Will that stretch the video too?

  2. I don't need the default play/forward/stop buttons at all. Basically I need continuous loop playing of the video.

I tried the MediaPlayer class as in here, but it never worked. What should the string format look like if I have my video file in res/raw directory? I really don't want the video file played from sdcard. How can it be bundled along with the app?

If any of these two approaches work, I will be better off.

This is my code:

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(); 

Strangely the commented url works (the one with sdcard). The other one does not work. I have tried many combinations from "file:// res/raw/demo.3gp" to only "demo".

What would be the correct string to access the file?

No need to do any coding for playing video to full screen mode

Apply the following layout format over the xml containing the videoview it will for sure will play the video in full screen mode. as it is running mine. :) Hope it helps

 <?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>

Plus adding the mediacontroller will also give you the controller to use.