api.video Android Upstream: camera + progressive upload
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.
Project description
This library is an easy way to capture your video and microphone and upload it to api.video at the same time.
Getting started
Installation
Gradle
On build.gradle add the following code in dependencies:
dependencies {
implementation 'video.api:android-upstream:1.1.0'
}
Permissions
<manifest>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
</manifest>
Your application must dynamically require android.permission.CAMERA
and android.permission.RECORD_AUDIO
.
Code sample
- Add permissions to your
AndroidManifest.xml
and request them in your Activity/Fragment. - Add a
ApiVideoView
to your Activity/Fragment layout for the camera preview.
<video.api.upstream.views.ApiVideoView android:id="@+id/apiVideoView"
android:layout_width="match_parent" android:layout_height="match_parent" />
- Create an
ApiVideoUpstream
instance in your fragment or activity.
class MyFragment : Fragment() {
private var apiVideoView: ApiVideoView? = null
private lateinit var upstream: ApiVideoUpstream
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val apiVideoView = view.findViewById(R.id.apiVideoView)
val audioConfig = AudioConfig(
bitrate = 128 * 1000, // 128 kbps
sampleRate = 44100, // 44.1 kHz
stereo = true,
echoCanceler = true,
noiseSuppressor = true
)
val videoConfig = VideoConfig(
bitrate = 4 * 1000 * 1000, // 4 Mbps
resolution = Resolution.RESOLUTION_720,
fps = 30
)
ApiVideoUpstream(
context = requireContext(),
apiKey = apiKey,
timeout = 60000, // 1 min
initialAudioConfig = audioConfig,
initialVideoConfig = videoConfig,
apiVideoView = apiVideoView
)
}
}
Create or get your video id or create or get an upload token from api.video Alternatively, you can create or get an upload token in the dashboard.
Start your record
If you are using video id:
upstream.startStreamingForVideoId("YOUR_VIDEO_ID")
If you are using an upload token:
upstream.startStreamingForToken("YOUR_UPLOAD_TOKEN")
For detailed information on this upstream library API, refers to API documentation.
Tips
- If a part of the video is not uploaded, you can resume the upload by creating a
new
MultiFileUploader
withApiVideoUpstream.loadExistingSession
. - You can check device supported configurations by using the helper:
Helper
Documentation
Sample application
A demo application demonstrates how to use this upstream library. See /example
folder.
Dependencies
We are using external library
Plugin | README |
---|---|
StreamPack | README.md |
FAQ
If you have any questions, ask us in the community or use issues.