android 实现视频播放功能,android开发之简单视频播放器(VideoView)

本文介绍了如何在Android中实现视频播放功能,包括使用VideoView和MediaController创建基本播放器,以及自定义播放器的详细步骤,包括布局设置、事件监听和屏幕方向变化的处理。
摘要由CSDN通过智能技术生成

简单视频播放器的使用

一、简单使用videoView和MediaController实现播放控制

1、添加需要的权限

2、设置布局

android:id="@+id/main_video"

android:layout_width="match_parent"

android:layout_height="240dp"

/>

3、实例化VideoView

VideoView videoView = (VideoView) findViewById(R.id.main_video);

MediaController controller = new MediaController(this);//实例化控制器

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

/**

* 本地播放

*/

// videoView.setVideoPath("path");

/**

* 网络播放

*/

videoView.setVideoURI(Uri.parse("http://192.168.1.109:8080/video/jiaoxue.mp4"));

/**

* 将控制器和播放器进行互相关联

*/

controller.setMediaPlayer(videoView);

videoView.setMediaController(controller);

二、自定义播放器 (贴上源码)

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.zzj.myeasyvideoplaydemo.MainActivity">

android:layout_width="match_parent"

android:layout_height="240dp">

android:id="@+id/main_video"

android:layout_width="match_parent"

android:layout_height="240dp"

/>

android:layout_width="match_parent"

android:layout_height="50dp"

android:orientation="vertical"

android:layout_alignParentBottom="true"

>

android:layout_width="match_parent"

android:layout_height="5dp"

android:layout_marginLeft="-20dp"

android:layout_marginRight="-20dp"

android:max="100"

android:indeterminate="false"

android:progress="20"

/>

android:gravity="center_vertical"

android:background="#101010"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal"

>

android:id="@+id/play_pasue_image"

android:layout_marginLeft="5dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@mipmap/video_play_

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值