您的位置:首页 > 移动开发 > Android开发

Android多媒体播放之视频播放的方法

2015-01-12 20:29 429 查看
public class VideoViewTest extends Activity {

	private VideoView vv;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.as);
		vv = (VideoView) findViewById(R.id.video);
		//设置播放视频文件的目录
		vv.setVideoPath(Environment.getExternalStorageDirectory().getAbsolutePath() + "/cc.mp4");
		//使用默认的视频控制器
		vv.setMediaController(new MediaController(this));
		//开始播放视频
		vv.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:orientation="vertical" >
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:onClick="download"
        />
    <VideoView 
        android:id="@+id/video"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: