android实现登录页面视频播放背景
2018-03-22 13:58
756 查看
一,准备需要播放的mp4文件
二,在res文件夹下新建raw文件夹,添加准备好的mp4文件
三, 在layout文件夹下新建一个布局文件 video_background.xml,[b]用于显示VideoView视频[/b]
背景mp4的布局文件 video_background.xml:<!--LoginActivity中include引用的样式-->
<?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"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="center" />
</RelativeLayout>[b]四,在主页面添加对[b]video_background.xml的引用[/b][/b]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.LoginActivity">
<!-- 引入背景布局 -->
<include layout="@layout/video_background" />
二,在res文件夹下新建raw文件夹,添加准备好的mp4文件
三, 在layout文件夹下新建一个布局文件 video_background.xml,[b]用于显示VideoView视频[/b]
背景mp4的布局文件 video_background.xml:<!--LoginActivity中include引用的样式-->
<?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"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="center" />
</RelativeLayout>[b]四,在主页面添加对[b]video_background.xml的引用[/b][/b]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.LoginActivity">
<!-- 引入背景布局 -->
<include layout="@layout/video_background" />
.......
</RelativeLayout>
五,在需要添加视频背景的activity中[b]OnCreate()方法中加入相关代码[/b]final VideoView videoview=(VideoView)findViewById(R.id.videoview);
final String videoPath = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.文件名).toString(); myVideoView.setVideoPath(videoPath); myVideoView.start(); myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.start(); mp.setLooping(true); } }); myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { myVideoView.setVideoPath(videoPath); myVideoView.start(); } });效果图列举一下喽:
相关文章推荐
- Android开发实现项目背景布局播放视频
- Android如何让WebView中的HTML5页面实现视频全屏播放
- [置顶] 简述Android中如何实现播放视频形式的引导页面
- 基于 Vue.js 2.0 酷炫自适应背景视频登录页面实现方式
- Android 仿QQ动态背景登录,Android用视频做背景的轻松实现
- android实现 布局背景播放视频
- Android的多媒体技术——MediaPlayer实现音频与视频的播放
- Android animation 动画背景图自动播放的实现
- Android动画背景图自动播放的实现
- Android中VideoView及SurfaceView视频播放实现
- Android 视频播放状态链控制简单实现
- JSP页面实现播放视频功能
- Android动画背景图自动播放的实现
- 模仿vine实现android视频的可间断录制和播放[basic]
- Android animation 动画背景图自动播放的实现
- android ViewPager 实现导航页面和广告播放
- Android之SurfaceView实现视频播放
- Android animation 动画背景图自动播放的实现
- Android动画背景图自动播放的实现
- 我的Android进阶之旅------>Android如何通过自定义SeekBar来实现视频播放进度条