Recorder

参考微信实现的短视频录像

预览

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    compile 'com.github.pye52:Recorder:1.0.4'
}

在manifest中添加

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>

<activity android:name="com.kanade.recorder.Recorder"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

如何使用

启动录像:

// 录像保存地址
String filepath = ....
Intent intent = Recorder.newIntent(context, filepath);
startActivityForResult(intent, requestCode)

获取返回结果:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
      if (data == null){
        return;
      }
    RecorderResult result = Recorder.getResult(data);
    // 录像文件保存地址
    String filepath = result.getFilepath();
    // 录像时长
    int duration = result.getDuration();
}

GitHub地址


团子吃蛋挞
72 声望1 粉丝

软粉