在android的中提供了一个VideoView组件,用于播放视频文件,要想使用VideoView播放视频,首先要在布局文件中创建改组件,然后在activity中获取该组件,调用VideoView中的start方法来播放视频。首先通过扫描SD卡找到SD卡中MP4和3gp个是的视频文件,放在一个listView列表中,点击listview的单元格实现对当前视频文件的播放。
下面放上主要的代码
1、xml文件
list.xml文件为视频列表布局文件,主要包括一个listview显示视频列表和一个更新视频按钮
<?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"
android:orientation="vertical" >
<TextView
android:id="@+id/updatevedio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="视频目录:"/>
<Button
android:id="@+id/updatevedioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="更新视频"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/updatevedio"
android:id="@+id/lv">
</ListView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:textSize="20sp"
android:text="C"/>
</RelativeLayout>
list_sd.xml文件为listview单元格布局文件,只是显示了一个视频名称,显示缩略图以后再做。
<?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:orientation="vertical" >
<TextView
android:layout_width="match_p