标签:
Android系统提供的VideoView视频播放组件非常方便。只需要三步:
1,在界面布局文件中定义VideoView组件
2,调用VideoView的setVideoPath(String path)或者setVideoURI(Uri uri)方法加载指定视频
3,调用VideoView的start(),stop(),pause()方法来操作视频
MediaController还提供了快进,暂停,后退,以及播放进度条,这样就不需要开发者自己去敲代码了。
1 package com.example.day19_02videoplayer2; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.os.Environment; 6 import android.widget.MediaController; 7 import android.widget.VideoView; 8 9 public class MainActivity extends Activity { 10 11 @Override 12 protected void onCreate(Bundle savedInstanceState) { 13 super.onCreate(savedInstanceState); 14 setContentView(R.layout.activity_main); 15 16 String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/sirendingzhi.mp4"; 17 18 VideoView video = (VideoView) findViewById(R.id.vv_video); 19 video.setVideoPath(path); 20 video.setMediaController(new MediaController(this)); 21 video.start(); 22 } 23 }
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:paddingBottom="@dimen/activity_vertical_margin" 6 android:paddingLeft="@dimen/activity_horizontal_margin" 7 android:paddingRight="@dimen/activity_horizontal_margin" 8 android:paddingTop="@dimen/activity_vertical_margin" 9 tools:context="com.example.day19_02videoplayer2.MainActivity" > 10 11 <VideoView 12 android:layout_height="fill_parent" 13 android:layout_width="fill_parent" 14 android:id="@+id/vv_video" 15 /> 16 17 </RelativeLayout>
当点击播放画面时,屏幕底端就会弹出MediaController
标签:
原文地址:http://www.cnblogs.com/woodrow2015/p/4543809.html