Android中实现跳转和视频播放:
MainAcivity.java代码:
import java.io.File;
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 StartActivity extends Activity {
private VideoView vv1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
// VideoView实例化
vv1 = (VideoView) findViewById(R.id.vv1);
// 获取开场动画文件的
File file = new File("/sdcard/sm.mp4");
// 设置要播放的音频
vv1.setVideoPath(file.getAbsolutePath());
// 让VideoView获得焦点
vv1.requestFocus();
// 开始播放视频
vv1.start();
// 添加VideoView完成事件监听器
vv1.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
// TODO Auto-generated method stub
// 进入游戏的主界面
Intent intent = new Intent(StartActivity.this,M1.class);
//启动新的Activity
startActivity(intent);
//结束当前Activity
StartActivity.this.finish();
}
});
}
}
start.xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<VideoView
android:id="@+id/vv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
|
|