如何在应用程序启动前播放视频?
我做了一个动画,显示了我的名字和应用程序的名称,我希望将此视频作为简介。
答案 0 :(得分:0)
尝试使用VideoView
。
请检查示例代码
package com.dwivedi.splashscreenexample;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.Bundle;
import android.widget.VideoView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
VideoView videoHolder = (VideoView)this.findViewById(R.id.videoView1);
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();
}
}
protected void jump() {
Intent intent = new Intent(this, HomeActivity.class);
startActivity(intent);
}
}