启动视频全屏问题android

时间:2014-10-07 08:13:19

标签: 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.view.WindowManager;
import android.widget.VideoView;

public class SplashActivity extends Activity {
    VideoView videoHolder;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,           
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        try{
            videoHolder = new VideoView(this);
            setContentView(videoHolder);
            Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
                    + R.raw.splash);
            videoHolder.setVideoURI(video);

            videoHolder.setOnCompletionListener(new OnCompletionListener() {

                public void onCompletion(MediaPlayer mp) {
                    jump();
                }

            });
            videoHolder.start();
        } catch(Exception ex) {
            jump();
        }
    }


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

我无法全屏查看启动视频...但它只是在上半部分......我应该做些什么更改才能使视频全屏显示为我工作请建议

2 个答案:

答案 0 :(得分:0)

onCreate方法更改:

@Override
public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);

  //Remove notification bar
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,           
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

try{
    videoHolder = new VideoView(this);
    setContentView(videoHolder);

    VideoView vd = (VideoView) findViewById(R.id.videoView);
    Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
            + R.raw.splash);
    videoHolder.setVideoURI(video);

    videoHolder.setOnCompletionListener(new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            jump();
        }

    });
    videoHolder.start();
} catch(Exception ex) {
    jump();
   }
}

这可能会解决您的问题。

答案 1 :(得分:0)

如果您只想使用{{}添加layout,则不使用 onCreate 中的setContentView方法使用VideoView(您在布局文件夹中创建) {1}}然后为该视频观看 height width 的布局参数设置为setContentView

如果你想使用布局做这样的事情

MATCH_PARENT