GithubHelp home page GithubHelp logo

bluthlee / audiorecorder Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 265 KB

Android audio recorder that can record audio and contain two styles of recorder view.

Kotlin 47.00% Java 53.00%
android-library audio-recorder kotlin audiorecorder record-audio aar android java

audiorecorder's Introduction

AudioRecorder

该库是一个录音模块,用于Android平台,分别有使用Java和Kotlin实现的两套代码,目前包含两种样式:DragAudioRecorder,FloatAudioRecorder.

DragAudioRecorder FloatAudioRecorder

Compatibility

最低API版本要求 API 15 (Android 4.0.3)

Download

在此下载最新的aar格式打包文件audio-recorder-kotlin-1.0.0.aar

另外需要额外引用一个Kotlin的库,在你的module的build.gradle文件中添加如下Kotlin库

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.4-2+"
}

Usage

使用相应AudioRecorder的子类Builder,如欲使用DragAudioRecorder,则需使用DragAudioRecorder.Builder 并对其进行配置,最后调用build方法构造一个AudioRecorder对象,然后可以对其进行操作,如显示和隐藏。

Builder的一般方法

setDirPath(dirPath:String): 设置存放录音文件的绝对路径

setFileName(fileName:String): 设置录音文件名(不含文件扩展名)

setOnFinishListener(listener:AudioRecorder.OnFinishListener): 设置录音完成的监听事件,在录音结束后会调用

AudioRecorder.OnFinishListener.onFinish(filePath:String): filePath为录音文件的绝对路径,如果录音取消或者失败则为空字符串""

DragAudioRecorder专有方法

DragAudioRecorder.Builder的方法:

setAttachedRecorderButton(view:View): 设置需要依附的view,例如使用一个button,会响应其触摸事件,按住button会弹出提示并开始录音

FloatAudioRecorder专有方法

FloatAudioRecorder.Builder的方法:

setContext(context:Context): 设置context

FloatAudioRecorder的方法:

show(): 显示录音控件

cancel(): 取消显示录音控件

isShowing(): 获取当前录音控件的显示状态

使用示例

//使用DragAudioRecorder
DragAudioRecorder.Builder
        //required
        .setAttachedRecorderButton(button1)

        //optional
        .setDirPath(dragDirPath)
        .setFileName(System.currentTimeMillis().toString() + "_drag")
        .setOnFinishListener(object : AudioRecorder.OnFinishListener {
            override fun onFinish(filePath: String) {
                Toast.makeText(this@MainActivity, filePath, Toast.LENGTH_SHORT).show()
            }
        })

        //build and initialize
        .build()
   
//使用FloatAudioRecorder
val floatAudioRecorder = FloatAudioRecorder.Builder
        //required
        .setContext(this)

        //optional
        .setDirPath(floatDirPath)
        .setFileName(System.currentTimeMillis().toString() + "_float")
        .setOnFinishListener(object : AudioRecorder.OnFinishListener {
            override fun onFinish(filePath: String) {
                Toast.makeText(this@MainActivity, filePath, Toast.LENGTH_SHORT).show()
            }
        })

        //build and initialize
        .build()
        
//get status
val isShowing=floatAudioRecorder.isShowing()
        
//show the recorder
floatAudioRecorder.show()        
        
//cancel the recorder
floatAudioRecorder.cancel()

audiorecorder's People

Contributors

bluthlee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.