android:播放宽屏视频

发布于 2024-11-28 19:13:08 字数 1745 浏览 2 评论 0原文

我开发了一个用于播放视频的应用程序..播放视频的代码在这里..

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.videoview);
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    filename = extras.getString("videofilename");
    mVideoView = (VideoView)findViewById(R.id.videoview);

    path=filename;
    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(
                ViewVideo.this,
                "Please edit VideoViewDemo Activity, and set path"
                        + " variable to your media file URL/path",
                Toast.LENGTH_LONG).show();

    } else {

          mVideoView.setVideoPath(path);
          mc = new MediaController(this);
          mVideoView.setMediaController(mc);
          mVideoView.requestFocus();
          mVideoView.bringToFront();
          mVideoView.start();

    }
}

这是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/videoview"
             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>

问题是当我尝试播放宽屏16:9视频时。它在全屏上显示它并且角色看起来被挤压。我需要以带有遮罩的宽屏格式播放(视频上方和下方有两个水平黑条)。 请问有什么建议吗?

I developed an application for playing video.. the code for playing video is here..

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.videoview);
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    filename = extras.getString("videofilename");
    mVideoView = (VideoView)findViewById(R.id.videoview);

    path=filename;
    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(
                ViewVideo.this,
                "Please edit VideoViewDemo Activity, and set path"
                        + " variable to your media file URL/path",
                Toast.LENGTH_LONG).show();

    } else {

          mVideoView.setVideoPath(path);
          mc = new MediaController(this);
          mVideoView.setMediaController(mc);
          mVideoView.requestFocus();
          mVideoView.bringToFront();
          mVideoView.start();

    }
}

Here is the xml code

 <?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/videoview"
             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>

The problem is that when I try to play a widescreen 16:9 video. It shows it on fullscreen and the characters appear squeezed. I need to play in widescreen format with mattes (two horizontal black bars above and below the video)..
Any suggestions please ??

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

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

发布评论

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

评论(2

独享拥抱 2024-12-05 19:13:08

这是相关问题

看起来您正在通过使用强制视频与屏幕的所有四个边对齐,

android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"

这会影响视频的宽高比。相反,尝试将其放入 LinearLayout 中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">

    <VideoView android:id="@+id/videoview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</LinearLayout>

Here's a related question.

It seems like you are forcing the video to align with all four sides of the screen by using

android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"

This is throwing off the aspect ratio of the video. Instead try putting it in a LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">

    <VideoView android:id="@+id/videoview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</LinearLayout>
伴我心暖 2024-12-05 19:13:08

尝试在垂直线性布局中使用 MediaViewer。

像这样的东西(在我的脑海中,所以不要隐含地相信它):

<LinearLayout android:layout_height="match_parent" 
    android:layout_width="match_parent" android:weightSum="9"
    android:orientation="vertical">
    <VideoView android:layout_height="0dp" android:layout_width="0dp"
        android:layout_weight="6" />
</LinearLayout>

这应该填满屏幕垂直区域的 2/3。

根据需要调整weightSum和layout_weight。

希望这有帮助!

Try using the MediaViewer in a vertical linearLayout.

Something like this (off the top of my head, so don't trust it implicitly):

<LinearLayout android:layout_height="match_parent" 
    android:layout_width="match_parent" android:weightSum="9"
    android:orientation="vertical">
    <VideoView android:layout_height="0dp" android:layout_width="0dp"
        android:layout_weight="6" />
</LinearLayout>

This should fill up 2/3 of the vertical area of the screen.

Adjust weightSum and layout_weight as desired.

Hope this helps!

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