您的位置:首页 > 其它

019_02视频播放之VideoView

2015-06-01 14:04 316 查看
  Android系统提供的VideoView视频播放组件非常方便。只需要三步:

1,在界面布局文件中定义VideoView组件

2,调用VideoView的setVideoPath(String path)或者setVideoURI(Uri uri)方法加载指定视频

3,调用VideoView的start(),stop(),pause()方法来操作视频

  MediaController还提供了快进,暂停,后退,以及播放进度条,这样就不需要开发者自己去敲代码了。



package com.example.day19_02videoplayer2;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String    path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/sirendingzhi.mp4";

VideoView video = (VideoView) findViewById(R.id.vv_video);
video.setVideoPath(path);
video.setMediaController(new MediaController(this));
video.start();
}
}


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.day19_02videoplayer2.MainActivity" >

<VideoView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/vv_video"
/>

</RelativeLayout>


当点击播放画面时,屏幕底端就会弹出MediaController

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