问题描述
我已经玩了一个多星期了,知道很多,但仍然缺乏大量知识.我正在尝试使用 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.
推荐答案
我设法做到了,下面给出了我的代码.首先列出的是Activity,然后是布局.
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>
如您所见,方向设置为横向,因此启动画面将始终以横向模式显示.将此活动的主题设置为 @android:style/Theme.NoTitleBar.Fullscreen 很重要.它使视频覆盖整个屏幕.了解 Android 无法将您的视频缩放到显示分辨率很重要.因此,如果您的视频分辨率与设备的分辨率不匹配,您会在视频的左侧/右侧或顶部/底部看到黑色边框 - 取决于您的视频分辨率.
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.
布局文件splash.xml的内容如下:
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>
这篇关于应用加载时全屏横向视频(启动画面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!