【问题标题】:Fullscreen landscape Video (splash screen) while app loads应用加载时的全屏横向视频(启动画面)
【发布时间】:2011-03-17 06:54:46
【问题描述】:

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

【问题讨论】:

  • 请告诉我你已经做到了我想做同样的事情
  • @Adam:你做到了吗?我正在尝试做同样的事情,但视频没有按照我想要的方式显示。

标签: android video splash-screen


【解决方案1】:

我设法做到了,下面给出了我的代码。首先列出的是 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>

如您所见,方向设置为横向,因此初始屏幕将始终以横向模式显示。将此活动的主题设置为@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>

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      • 2020-12-05
      相关资源
      最近更新 更多