如何设置视频全屏

发布于 2024-10-04 02:18:40 字数 3103 浏览 3 评论 0 原文

你好,如何将视频设置为全屏现在我附上我的屏幕截图....

alt text

alt text

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="videothumb.videothumb"
  android:versionCode="1"
  android:versionName="1.0">
 <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".videothumb" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

   <activity android:name="ViewVideo" android:label="@string/app_name"    
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
   <intent-filter><action android:name="android.intent.action.VIEW"></action>
   <category android:name="android.intent.category.DEFAULT"></category>
   </intent-filter>
   </activity>

   </application>
   <uses-sdk android:minSdkVersion="8" />
   <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS">
   </uses-permission>
   </manifest> 

ViewVideo.java

package videothumb.videothumb;


import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.GridView;
import android.widget.MediaController;
import android.widget.VideoView;

public class ViewVideo extends Activity {
  private String filename;
  private VideoView Video;
  @Override
  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main1);
        Video=(VideoView)findViewById(R.id.VideoView01);
        System.gc();
        Intent i = getIntent();
        Bundle extras = i.getExtras();
        filename = extras.getString("videofilename");
        Video.setVideoPath(filename);
        Video.setMediaController(new MediaController(this));
        Video.requestFocus();
        Video.start();
    }

  } `

xml编码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<VideoView 
android:id="@+id/VideoView01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent">
</VideoView>
</LinearLayout>

hai how set video in full screen now i am attach my screen shot....

alt text

alt text

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="videothumb.videothumb"
  android:versionCode="1"
  android:versionName="1.0">
 <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".videothumb" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

   <activity android:name="ViewVideo" android:label="@string/app_name"    
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
   <intent-filter><action android:name="android.intent.action.VIEW"></action>
   <category android:name="android.intent.category.DEFAULT"></category>
   </intent-filter>
   </activity>

   </application>
   <uses-sdk android:minSdkVersion="8" />
   <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS">
   </uses-permission>
   </manifest> 

ViewVideo.java

package videothumb.videothumb;


import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.GridView;
import android.widget.MediaController;
import android.widget.VideoView;

public class ViewVideo extends Activity {
  private String filename;
  private VideoView Video;
  @Override
  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main1);
        Video=(VideoView)findViewById(R.id.VideoView01);
        System.gc();
        Intent i = getIntent();
        Bundle extras = i.getExtras();
        filename = extras.getString("videofilename");
        Video.setVideoPath(filename);
        Video.setMediaController(new MediaController(this));
        Video.requestFocus();
        Video.start();
    }

  } `

xml coding:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<VideoView 
android:id="@+id/VideoView01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent">
</VideoView>
</LinearLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天赋异禀 2024-10-11 02:18:40

您是否尝试过:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

在包含媒体播放器代码的类中。

在你的 xml 中

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

我希望这会对你有所帮助。

Have you tried this:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

in your class that contains mediaplayer code.

and in your xml

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

I hope this will help you.

寄居者 2024-10-11 02:18:40

无需代码即可全屏模式播放视频

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

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

No need of code to play video in 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>
玩心态 2024-10-11 02:18:40

我的 java 文件:

public class VideoViewDemo extends Activity {

VideoView mVideoView;
MediaController mc;
@Override
public void onCreate(Bundle icicle) {
   super.onCreate(icicle);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//if you want.
    File video = new File("your file path");
    mVideoView = (VideoView) findViewById(R.id.surface);
    mc = new MediaController(this);
    mVideoView.setMediaController(mc);
    mc.setAnchorView(mVideoView);
    mVideoView.setMediaController(mc);
    mVideoView.setVideoPath(video.getAbsolutePath());
    mVideoView.requestFocus();
    mVideoView.start();

}                                                                                        

我的 xml 布局:

和我的 Menifest 文件:

my java file:

public class VideoViewDemo extends Activity {

VideoView mVideoView;
MediaController mc;
@Override
public void onCreate(Bundle icicle) {
   super.onCreate(icicle);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//if you want.
    File video = new File("your file path");
    mVideoView = (VideoView) findViewById(R.id.surface);
    mc = new MediaController(this);
    mVideoView.setMediaController(mc);
    mc.setAnchorView(mVideoView);
    mVideoView.setMediaController(mc);
    mVideoView.setVideoPath(video.getAbsolutePath());
    mVideoView.requestFocus();
    mVideoView.start();

}                                                                                        

my xml layout:

and my Menifest file:

快乐很简单 2024-10-11 02:18:40

顺便说一句,在您的清单中,在这一行 中,您忘记在“ViewVideo”之前添加一个点(.)。应该是“.ViewVideo”

By the way, in your manifest, at this line <activity android:name="ViewVideo",you forgot to put a dot(.) before the "ViewVideo". It should be ".ViewVideo"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文