Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.techery:opus_android:'
}
dependencies {
implementation("com.github.techery:opus_android:")
}
<dependency>
<groupId>com.github.techery</groupId>
<artifactId>opus_android</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.techery" % "opus_android" % ""
:dependencies [[com.github.techery/opus_android ""]]
Welcome to the Opus library for Android.
This is an Android library transplanted from official Opus codec. With this library, Opus format audio can be operated in an easy way. Application level function includes audio record, playback, encode and decode.
Add the following dependency to your project.
compile 'top.oply.opuslib:opuslib:1.0.2'
OpusService is the highest level interface to programmer. It's a background Server running automatically. All you need to do is sending Intents to it, and receiving the feedback messages through a Broadcast Receiver. The approach is recommended over the Method 2.
Many static public method can be called directly. For details, please refer to the source code of OpusService.java
OpusService.play(Context context, String fileName);
OpusService.record(Context context, String fileName);
......
A Broadcast Receiver is needed to receive the feadback messages while playing, recording or converting a opus file. Below is an example.
//register a broadcast receiver
mReceiver = new OpusReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(OpusEvent.ACTION_OPUS_UI_RECEIVER);
registerReceiver(mReceiver, filter);
//define a broadcast receiver
class OpusReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
int type = bundle.getInt(OpusEvent.EVENT_TYPE, 0);
switch (type) {
case OpusEvent.CONVERT_FINISHED:
break;
case OpusEvent.CONVERT_FAILED:
break;
case OpusEvent.CONVERT_STARTED:
break;
case OpusEvent.RECORD_FAILED:
break;
case OpusEvent.RECORD_FINISHED:
break;
case OpusEvent.RECORD_STARTED:
break;
case OpusEvent.RECORD_PROGRESS_UPDATE:
break;
case OpusEvent.PLAY_PROGRESS_UPDATE:
break
case OpusEvent.PLAY_GET_AUDIO_TRACK_INFO:
break
case OpusEvent.PLAYING_FAILED:
break;
case OpusEvent.PLAYING_FINISHED:
break;
case OpusEvent.PLAYING_PAUSED:
break;
case OpusEvent.PLAYING_STARTED:
break;
default:
Log.d(TAG, intent.toString() + "Invalid request,discarded");
break;
}
}
}
OpusTool oTool = new OpusTool();
oTool.decode(fileName,fileNameOut, null);
oTool.encode(fileName, fileNameOut, null);
OpusPlayer opusPlayer = OpusPlayer.getInstance();
opusPlayer.play(fileName);
opusPlayer.stop();
OpusRecorder opusRecorder = OpusRecorder.getInstance();
opusRecorder.startRecording(fileName);
opusRecorder.stopRecording();
Well, you can stop reading if you don't need to modify the library code. Your project should be working if you follow the steps above.
##Project Compilation
pre-requisites
JDK v1.8 or higher
Android Studio (with SDK) 1.2.1 or higher
Summary of set up:
Get the source code.[Git] (https://github.com/louisyonge/opus_android.git)
2 remember to export NDK's path. Take Linux for example, add the following code to the end of the file "/etc/profile", and then reboot your system.
NDK_ROOT=/usr/local/lib/android-ndk-r9d
export PATH=$NDK_ROOT:$PATH
Compile and run.
Testing Hints:
This demo use external storage to store audio file. Be sure your Android device has a SD card when testing this demo. You could also store them in internal storage by changing source code.
SDK, NDK, Android Studio, Eclipse
Note: Android Studio 1.2 does not support the debug of Native code. So it is wise to develop the C&C++ code in Eclipse. For this project, codes under the folder "OpusPlayer\opuslib\src\main\jni" are Native codes. The rest of this project is Java codes, developed by Android Studio.(deprecated)
Opus (git://git.opus-codec.org/opus.git)
Opus-tools (git://git.xiph.org/opus-tools.git)
Opusfile (git://git.xiph.org/opusfile.git)
##Licence
Project uses Apache 2.0 License
###Have fun!