应用程序加载时的全屏横向视频(启动画面)

发布于 2024-10-24 02:05:49 字数 170 浏览 5 评论 0原文

我已经在 Android 上摆弄了一个多星期了,知道了相当多的知识,但仍然缺乏大量的知识。我正在尝试使用 mp4 作为启动画面电影活动。我被告知使用的方法都给我带来了可怕的效果。我想要一部全屏水平/横向电影,设备上除了电影之外什么都没有……没有视频控件等。我还希望视频能够被点击和销毁。如果您能提供帮助,我将非常感谢您的努力。

I have been messing around with android for a little over a week now and know a fair amount, yet still lack a ton of knowledge. I am trying to use an mp4 as a splash screen movie activity. And the methods I was told to use all give me a horrible effect. I want a fullscreen horizontal/landscape movie with nothing on the device except the movie...no video controls etc.. I also want the video to be able to be clicked on and destroyed. If you could help I would greatly appreciate any efforts.

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

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

发布评论

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

评论(2

半仙 2024-10-31 02:05:49

我设法做到了这一点,下面给出的是我的代码。首先列出的是 Activity,然后给出布局。

package com.adnan.demo;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.widget.VideoView;

public class Splash extends Activity implements OnCompletionListener
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        VideoView video = (VideoView) findViewById(R.id.videoView);
        video.setVideoPath("android.resource://com.agileone/raw/" + R.raw.splash);
        video.start();
        video.setOnCompletionListener(this);
    }

    @Override
    public void onCompletion(MediaPlayer mp)
    {
        Intent intent = new Intent(this, Home.class);
        startActivity(intent);
        finish();
    }
}

该活动在清单文件中声明如下:

<activity android:name=".Splash" android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

如您所见,方向设置为横向,因此启动屏幕将始终以横向模式显示。将此 Activity 的主题设置为 @android:style/Theme.NoTitleBar.Fullscreen 很重要。它使视频覆盖整个屏幕。重要的是要了解 Android 无法将视频缩放到显示器分辨率。因此,如果您的视频分辨率与设备的分辨率不匹配,您将在视频的左/右或顶部/底部看到黑色边框 - 具体取决于您的视频分辨率。

布局文件splash.xml的内容如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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_gravity="center"
        android:layout_width="fill_parent" android:layout_height="fill_parent"/>

</FrameLayout>

I managed to do this and given below is my code for it. First listed is the Activity and later the layout is given.

package com.adnan.demo;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.widget.VideoView;

public class Splash extends Activity implements OnCompletionListener
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        VideoView video = (VideoView) findViewById(R.id.videoView);
        video.setVideoPath("android.resource://com.agileone/raw/" + R.raw.splash);
        video.start();
        video.setOnCompletionListener(this);
    }

    @Override
    public void onCompletion(MediaPlayer mp)
    {
        Intent intent = new Intent(this, Home.class);
        startActivity(intent);
        finish();
    }
}

The activity is declared in the manifest file as follows:

<activity android:name=".Splash" android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

As you can see the orientation is set to landscape so the splash screen will always appear in landscape mode. Setting the theme of this activity to @android:style/Theme.NoTitleBar.Fullscreen is important. It makes the video to cover the whole screen. It is important to understand that Android cant scale your video to the displays resolution. So if your videos resolution does not match the device's resolution, you will see black borders to left/right or top/bottom of the video - depending on your videos resolution.

The contents of the layout file splash.xml are given below:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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_gravity="center"
        android:layout_width="fill_parent" android:layout_height="fill_parent"/>

</FrameLayout>
凉薄对峙 2024-10-31 02:05:49

不要对包名称进行硬编码。
相反你可以这样做
"android.resource://" + getPackageName() + "/"+R.raw.VideoName

Dont hardcode the package name.
Instead you could do this
"android.resource://" + getPackageName() + "/"+R.raw.VideoName

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