应用程序加载时全屏风景视频(启动画面)

1 video android splash-screen

我现在已经用了一个多星期的时间搞乱了android并知道了相当多的数量,但仍然缺乏大量的知识.我正在尝试使用mp4作为启动画面电影活动.我被告知使用的方法都给我带来了可怕的影响.我想要一个全屏横向/横向电影,除了电影之外没有任何设备......没有视频控制等.我也希望能够点击和销毁视频.如果你能提供帮助,我将非常感谢任何努力.

bin*_*inW 5

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

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

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

<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>
Run Code Online (Sandbox Code Playgroud)

如您所见,方向设置为横向,因此启动屏幕将始终以横向模式显示.将此活动的主题设置为@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>
Run Code Online (Sandbox Code Playgroud)