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还提供了快进,暂停,后退,以及播放进度条,这样就不需要开发者自己去敲代码了。
当点击播放画面时,屏幕底端就会弹出MediaController
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
相关文章推荐
- 产品经理经常犯的十大顶级错误
- SAT阅读常见问题及解题方法
- powerdesigner和MySQL生成ER图
- Deep Learning(深度学习)学习系列之(三)
- ubuntu账户添加和删除
- SqlBulkCopy的一个例子
- ember相关组件
- 创始人“姬十三”说,科学和教育都能让果壳赚到钱
- Pool of Argument Topics 41-50
- Nginx反向代理Tomcat的配置方法
- 基于spark1.3.1的spark-sql实战-02
- 第十三周 程序阅读二
- 深入理解python之self
- Android项目框架搭建 (分析需求、整理资料)
- ember相关组件
- ember相关组件
- 微软Windows 10原生支持Dolby Audio
- 第十三周项目1——动物这样叫
- JavaScript之闭包
- 驴妈妈获锦江集团5亿元战略投资