Android 作为splash的视频

Android 作为splash的视频,android,android-layout,android-video-player,Android,Android Layout,Android Video Player,我想将原始文件夹中的视频文件作为splash播放。但它不起作用。有人能帮我解决这个问题吗 这是我的密码 public class SplashActivity extends Activity implements OnCompletionListener{ private MediaController mc; @Override public void onCreate(Bundle savedInstanceState) { super.onCr

我想将原始文件夹中的视频文件作为splash播放。但它不起作用。有人能帮我解决这个问题吗

这是我的密码

public class SplashActivity extends Activity implements OnCompletionListener{

    private MediaController mc;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        VideoView vd = (VideoView) findViewById(R.id.VideoView);
        Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"+R.raw.sea);
        //mc = new MediaController(this);
        //vd.setMediaController(mc);
        vd.requestFocus();
        vd.setVideoURI(uri);
        vd.start();
        // vd.setOnCompletionListener(this);
    }

    public void onCompletion(MediaPlayer mp) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
我的布局是:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:gravity="center">

  <VideoView android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:id="@+id/VideoView">
  </VideoView>

< /LinearLayout>



问题出在哪里。。正在播放视频否。显示错误为抱歉,此视频无法显示07-30 15:48:57.460:I/VideoView(18540):设置大小:320x480 07-30 15:48:57.476:E/MediaPlayer(18540):错误(1,-22)07-30 15:48:57.476:E/MediaPlayer(18540):错误(1,-22)07-30 15:48:57.484:D/VideoView(18540):错误:1,-22 0@user2159490是在
仿真器
真实设备
上测试此功能?视频的类型是什么?(3gp、mp4等)在真实设备上测试,文件类型为mp4,持续时间为5秒,大小为4.63mb sizemSplashVideoPath=Environment.getExternalStorageDirectory()+路径;什么是路径?解释一下。。。
public class SplashActivity extends Activity{

    private String mSplashVideoPath;

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

        setContentView(R.layout.splash);

        mSplashVideoPath = Environment.getExternalStorageDirectory() + PATH;

        copyVideoFile();

        final VideoView mVideoView = (VideoView) findViewById(R.id.videoView);
        mVideoView.requestFocus();
        mVideoView.setVideoPath(mSplashVideoPath);
        mVideoView.start();

        mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mediaPlayer) {

                startActivity(new Intent(SplashActivity.this, MainActivity.class));

                finish();
            }
        });
    }

    private void copyVideoFile() {
        final File videoPath = new File(mSplashVideoPath);

        if (!videoPath.exists()) {
            videoPath.mkdirs();
        }

        final File videoFile = new File(mSplashVideoPath);

        if (!videoFile.exists()) {
            AssetManager assetManager = getAssets();
            InputStream in = null;
            OutputStream out = null;
            try {
                in = assetManager.open(ASSETS_SPLASH_VIDEO);
                out = new FileOutputStream(videoFile);
                copyFile(in, out);
                in.close();
                in = null;
                out.flush();
                out.close();
                out = null;
            } catch(IOException e) {
                e.printStackTrace();
            }
        }
    }

    private void copyFile(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[1024];
        int read;
        while((read = in.read(buffer)) != -1){
            out.write(buffer, 0, read);
        }
    }
}