LiveStyler SDK for Android
This SDK is for applying LiveStyler features to Android applications. The SDK provides functionality to initialize the camera, send the captured video, and receive and display the video after processing is complete.
Getting Started
Requirements
- Android 9.0 or higher
- AGP 8.0 or higher
- Kotlin 1.7.21 or higher
Key Features
- Control video conversion through a signaling channel
- Send camera video to a WebRTC server
- Receive video with filters applied
Installation
Gradle
// root/build.gradle
allprojects {
repositories {
...
maven {
url = uri("https://maven.pkg.github.com/dob-world/livestyler-sdk-android")
credentials {
username = System.getenv("GITHUB_USERNAME") ?: "{username}"
password = System.getenv("GITHUB_TOKEN") ?: "{PAT}"
}
}
...
}
}
username: Github 사용자 계정PAT: Github Personal Access Token
// app/build.gradle
dependencies {
implementation "ai.livestyler:livestyler-sdk-android:latest.release"
}
Then execute the following command:
How to Use
Easy Usage
You can use the pre-implemented StreamFragment.
// Initialization
val args = Bundle().apply {
putString("credential", "{credential}") // Authentication token issued through the admin page
putString("apiEndpoint", "{apiEndpoint}") // API server to get service information
putString("signalEndpoint", "{signalEndpoint}") // Signaling channel endpoint address for exchanging authentication information with the backend
putParcelableArrayList(
"serverEndpoints", // Set STUN and TURN servers, recommended to use the provided Google STUN server
arrayListOf(
Bundle().apply {
putString("type", "stun")
putString("endpoint", "stun:stun.l.google.com:19302") // STUN server address
},
Bundle().apply {
putString("type", "turn")
putString("endpoint", "{turnEndpoint}") // TURN server address
putString("username", "{username}") // TURN server authentication information
putString("password", "{password}") // TURN server authentication information
},
Bundle().apply {
putString("type", "turn")
putString("endpoint", "{turnEndpoint}") // TURN server address
putString("username", "{username}") // TURN server authentication information
putString("secret", "{secret}") // TURN server authentication information
}
)
)
putString("iceTransportsType", "{iceTransportsType}") // Specify the Peer-to-peer connection method using one of the values: All, NoHost, Relay
}
findNavController().navigate(R.id.action_HostFragment_to_StreamFragment, args = args)
Custom Development
For additional features not provided in the easy usage, or for custom implementation of UI/UX, it is recommended to implement it yourself.
Please refer to the Key Feature Specifications described later for usage instructions.
If you want to change the design and functionality of the screen, please refer to the StreamFragment.kt file and the fragment_stream.xml file.
For detailed API specifications, please refer to Android APIs.
Key Feature Specifications
You can create and implement screen functions yourself using the API.
LiveStylerManager
// Initialization
// Use the same values for accessKey, signalEndpoint, serverEndpoints as used when creating args
val liveStylerManager: LiveStylerManager = LiveStylerManager(
"{credential}",
"{apiEndpoint}",
"{signalEndpoint}",
listOf( {serverEndpoints} ),
"{iceTransportsType}"
)
onCreate()
Performs necessary tasks during initialization.
override fun onCreate(saveInstance?: Bundle) {
super.onCreate(saveInstance)
liveStyleManager.onCreate(requireContext(), this)
}
onCreateView()
Performs necessary tasks before the view is created.
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentStreamBinding.inflate(inflater, container, false)
liveStylerManager.onCreateView(this, this)
return binding.root
}
onViewCreated()
Passes the created view to the manager. You can selectively add a camera preview or a render preview.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
liveStylerManager.onViewCreated(binding.preview, binding.renderView)
}
onPause()
Stops camera capture.
onResume()
Resumes camera capture. Resets the signal server connection and WebRTC connection.
onStop()
Releases camera resources. Disconnects from the signal server and WebRTC and waits.
onDestroy()
Completely terminates the signal server connection and WebRTC connection.
override fun onDestroyView() {
liveStylerManager.onDestroy()
_binding = null
super.onDestroyView()
}
changeFilter(String)
Changes the filter set on the WebRTC server.
- filter_id: The ID of the filter you want to change from the filter list received via the API.
switchCamera(String)
Switches to the camera with the received camera ID. The camera ID can be obtained through the CameraManager.
- camera_id: The ID of the camera obtained through CameraManager (Android system tool).
updateFilterCategory()
Updates the filter and category lists by fetching them from the API server. The filter list is automatically updated upon connecting to the signal server. The updated list is delivered through the SignalStateListener.
changeModel(String)
Changes the filter model to the received model name. Use the model name found in the filter information (FilterCategoryData) obtained through the onReceivedFilterList() callback.
- model_name: The model name from FilterCategoryData.
The Android SDK includes processing to fetch the model list via the API.
However, the API reflected in the SDK is a service provided by LiveStyler, so there may be differences from the actual service.
The API may vary depending on the service configuration, so please refer to the API guide to check and use the model list.