启动页面播放视频
启动页面播放视频超简单实现方案:
- studio中的res目录下创建raw文件夹
- 将3gp或mp4格式的视频文件放入
代码部分
主要布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:padding="10dp"
android:layout_marginLeft="100dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:text="开始体验"
android:gravity="center"
android:textColor="@android:color/black"
android:background="@drawable/bg_border"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
主要代码文件:
public class Videoplayer extends Activity {
public static final String TAG = "Videoplayer";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 全屏显示
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.aty_video);
/*主要代码起始位置*/
final VideoView vv = (VideoView) this.findViewById(R.id.videoView);
final String uri = "android.resource://" + getPackageName() + "/" + R.raw.loader;
vv.setVideoURI(Uri.parse(uri));
vv.start();
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
mp.setLooping(true);
}
});
vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
vv.setVideoURI(Uri.parse(uri));
vv.start();
}
});
/*主要代码结束位置*/
}