MediaRecorder录制视频

本文介绍如何使用Android的MediaRecorder类进行视频录制,包括MainActivity的实现、权限管理、以及在Main2Activity中播放视频的步骤。同时,提供了针对Android 6.0及以上版本动态权限管理的工具类CommonUtil。
摘要由CSDN通过智能技术生成

MediaRecorder

这个类主要用来做多媒体录音和录视频的

首先是录制视频的mainActivity.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="8">
        <SurfaceView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/surfaceview"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <Button
            android:id="@+id/stop"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="暂停"
            android:layout_weight="1"/>
        <Button
            android:id="@+id/start"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="开始"
            android:layout_weight="1"/>
        <Button
            android:id="@+id/starting"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="播放"
            android:onClick="btnClick"
            android:layout_weight="1"/>
    </LinearLayout>

</LinearLayout>

然后是录制视频的MainActivity类

这个类中有一个if判断这个判断是用来获取Android 6.0以上版本的动态权限


public class MainActivity extends AppCompatActivity implements Surfac
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值