1.MainActivity.java

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private VideoView videoView;
private Button btn_start;
private Button btn_pause;
private Button btn_stop; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
} private void initView() {
videoView = (VideoView) findViewById(R.id.videoView);
btn_start = (Button) findViewById(R.id.btn_start);
btn_pause = (Button) findViewById(R.id.btn_pause);
btn_stop = (Button) findViewById(R.id.btn_stop); btn_start.setOnClickListener(this);
btn_pause.setOnClickListener(this);
btn_stop.setOnClickListener(this); //根据文件路径播放
videoView.setVideoPath("/sdcard/TopGirl.mp4");
videoView.setMediaController(new MediaController(this));
} @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_start:
videoView.start();
break;
case R.id.btn_pause:
videoView.pause();
break;
case R.id.btn_stop:
videoView.stopPlayback();
break;
}
}
}

2.activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp"> <VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="300dp" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <Button
android:id="@+id/btn_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="开始" /> <Button
android:id="@+id/btn_pause"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="暂停 " /> <Button
android:id="@+id/btn_stop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="停止" />
</LinearLayout> </LinearLayout>

最新文章

  1. 分享一款自己改进的皮肤“verdant”.
  2. 十分钟了解分布式计算:Google Dataflow
  3. AWS re:Invent 2014回顾
  4. BZOJ 1087 【SCOI2005】 互不侵犯King
  5. Bridge(桥接)-对象结构型模式
  6. 项目开发中遇到的extjs常见问题
  7. bzoj4561: [JLoi2016]圆的异或并
  8. GCC笔记
  9. blocked because of many connection errors; unblock with 'mysqladmin flush-hosts;MySQL在远程访问时非常慢的解决方法;MySql链接慢的解决方法
  10. SkyEye的使用
  11. sr4000自带API和opencv结合获取图像
  12. Linux的nginx环境的vue 部署
  13. “《编程珠玑》(第2版)第2章”:A题(二分搜索)
  14. ArcGis Classic COM Add-Ins插件开发的一般流程 C#
  15. mybatis-generator 自动生成mapper以及实体类
  16. web安全系列1:入侵的途径
  17. iOS之iOS11、iPhone X、Xcode9 适配指南
  18. bcolz的新操作
  19. java课上测试心得
  20. javascript类式继承函数最优版

热门文章

  1. Linux 解压压缩命令
  2. Android Sqlite 批量插入性能优化
  3. Python — 多线程与多进程
  4. 分布式_理论_05_ 一致性算法 Paxos
  5. java学习笔记 --- IO流小结
  6. @angular/cli项目构建--httpClient
  7. 马拉车——模版+KMP——模版
  8. mysql_union all 纵向合并建表_20170123
  9. 服务端缓存页面及IIS缓存设置
  10. [Wc2009]shortest