api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.
When it comes to Real-Time Messaging Protocol (RTMP), the most popular implementation is the C library: librtmp. However, if you are streaming from Android and want to use librtmp, you need to go through the following painful steps:
- compile librtmp for all Android architectures to generate multiple shared libraries
- write a code that links the librtmp C functions to the Java classes/methods using Java Native Interface (JNI)
- write Java classes/methods
rtmpdroid has been built to address this pain: you can directly use librtmp in your Android application like any other Java/Kotlin library.
rtmpdroid also comes with a minimalist Action Message Format (AMF) encoder that is included in librtmp.
In build.gradle, add the following code:
dependencies {
implementation 'video.api:rtmpdroid:1.2.1'
}
val rtmp = Rtmp()
rtmp.connect("rtmp://broadcast.api.video/s/YOUR_STREAM_KEY")
rtmp.connectStream()
while (true) {
val flvBuffer = getNewFlvFrame() // flvBuffer is a direct ByteBuffer
rtmp.write(flvBuffer)
}
val amfEncoder = AmfEncoder()
amfEncoder.add("myParam", 3.0)
val ecmaArray = EcmaArray()
ecmaArray.add("myOtherParam", "value")
amfEncoder.add(ecmaArray)
val amfBuffer = amfEncoder.encode()
<manifest>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
The default version of rtmpdroid
comes with the following shared libraries:
- librtmp.so
- libssl.so
- libcrypto.so
- librtmpdroid.so
However, your application might already use libssl
and libcrypto
. In this case, you can use the
packed version of rtmpdroid
. It only contains only librtmpdroid.so
and the other libraries are
contains in this library.
To use the packed version, add a -packed
suffix to the rtmpdroid
version in your build.gradle
:
dependencies {
implementation 'video.api:rtmpdroid:1.2.0-packed'
}
If you have any questions, ask us in https://community.api.video or use Issues.