Android VideoView 启动画面

标签 android android-videoview splash-screen

这是我的 splash.java,我使用我的 videoView 作为 contentView。有什么办法可以让视频在 contentView 的 videoView 中居中?

或者更好的做法是什么?

package com.android;

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

public class Splash extends Activity
{
    VideoView vidHolder;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        try
        {
            vidHolder = new VideoView(this);
            setContentView(vidHolder);
            Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.splash);
            vidHolder.setVideoURI(video);
            vidHolder.setOnCompletionListener(new OnCompletionListener()
            {
                public void onCompletion(MediaPlayer mp) {
                    jump();
            }});
            vidHolder.start();

        } catch(Exception ex) {
            jump();
        }
    }

    private void jump()
    {
        if(isFinishing())
            return;
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }
}

最佳答案

使用布局文件:

<?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/myvideo"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerInParent="true"/>
</RelativeLayout>

注意:您没有要求它,但您的代码来自其他地方看到的示例,该示例将在视频前后出现臭名昭著的黑色闪光。您需要添加 vidHolder.setZOrderOnTop(true); 以避免这种情况(在 #setVideoUri 之后)。

关于Android VideoView 启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19489361/

相关文章:

javascript - Windows 8 : Wait until setup tasks complete before tearing down extended splash screen

android - 在fragment中调用Camera Service,如何处理回调?

java - GLES 3.0 安卓工作室

java - 如何将修改 View 的代码移至主类

Android 视频不适合视频 View 的纵向宽度并且不占用横向全屏

ios - 启动屏幕不显示 iOS 8

java - 如何在android honeycomb中编辑EditTextPreference?

android - android TV 中的 videoview 屏幕变黑

android - 无法在 VideoView 上播放此视频

ios - 如何在 Storyboard中加载标签栏 Controller 之前初始化自定义启动画面?