- Overview
- Prerequisites
- Get video player
- Prepare video player
- Release video player
- Set event callback
- Add video playlist
- Manage video player actions
- Add audio track
- Manage effects
This guide helps you quickly integrate the Playback API into your project. You'll learn core features and build common use cases for video editing applications.
Complete Installation.
Access VideoPlayer instance from Video Editor API module:
import org.koin.android.ext.android.inject
class SampleActivity : AppCompatActivity() {
private val videoPlayer: VideoPlayer by inject()
// ...
} viewModel {
PlaybackViewModel(
+ videoPlayer = get()
)
}VideoPlayer requires a SurfaceView and its SurfaceHolder for video rendering.
- Prepare with video size
videoPlayer.prepare(videoSize) // Returns true if successful- Set surface holder
videoPlayer.setSurfaceHolder(surfaceHolder)Note: Check logs with tag BanubaVideoPlayer if preparation fails.
Monitor playback state and position changes:
videoPlayer.setCallback(videoPlayerCallback)See supported callback methods
Always release resources when leaving the screen (e.g., in Activity.onDestroy):
videoPlayer.clearSurfaceHolder(surfaceHolder)
videoPlayer.release()Use VideoPlayer.setVideoRanges with a list of VideoRecordRange objects:
videoPlayer.setVideoRanges(videoRangesList)// Convert each video Uri to VideoRecordRange with required properties
// Validate each source - player logs unsupported formats❗Important
Supports device-stored media formats.
Core playback controls:
Use videoPlayer.play to play video when VideoPlayer is prepared and video playlist is set
videoPlayer.play(shouldRepeat) // true - repeat playingExample: Seek to position
videoPlayer.seekTo(3000L) // Seek to 3rd secondAdd external audio tracks on top of video soundtrack:
// Convert audio Uri to MusicEffect instancevideoPlayer.setMusicEffects(tracks) // List<MusicEffect>The API requires you to implement effect management. Use VideoEffectsHelper for effect creation.
Effect List Management
val effects = mutableListOf<TypedTimedEffect<*>>()
// Add/remove effects based on user actions
videoPlayer.setEffects(effects)exclamation:Important
License token determines allowed FX and Speed effects. Using disallowed effects may cause crashes.
Apply color filter from assets:
val colorEffectFile = context.copyFromAssetsToExternal("color_filter_example.png")
val videoSize = Size(1024, 768)
val effect = VisualTimedEffect(VideoEffectsHelper.createLutEffect(colorEffectFile.path, videoSize))Create Rapid or SlowMo speed effects.
val rapidEffect = SpeedTimedEffect(VideoEffectsHelper.createSpeedEffect(2F)) // 2x speed
val slowMoEffect = SpeedTimedEffect(VideoEffectsHelper.createSpeedEffect(0.5F)) // 0.5x speedApply visual effects (check license for availability):
val fxName = "VHS"
val availableList = VideoEffectsHelper.provideVisualEffects(context)
val vhsDrawable = availableList.find {
context.getString(it.nameRes) == fxName
}?.provide() ?: throw Exception("VHS video effect is not available!")
if (vhsDrawable !is VisualEffectDrawable) throw TypeCastException("Drawable is not IVisualEffectDrawable type!")
val vhsEffect = VisualTimedEffect(effectDrawable = vhsDrawable)Add animated stickers (GIF):
val stickerUri = context.copyFromAssetsToExternal("example.gif").toUri()
val x = 100f
val y = 100f
val width = 100f
val height = 100f
val scale = 1f
val rotation = 20
val rectParams = RectParams().apply { setCoordinates(x, y, width, height, scale, rotation) }
val stickerEffect = VisualTimedEffect(
effectDrawable = VideoEffectsHelper.createGifEffect(
UUID.randomUUID(),
stickerUri,
rectParams
)
)💡 Hint
If you use sticker services as GIPHY you should download sticker as .gif file to the device and
then use this file to create the effect.
Add custom text overlay:
val width = 800
val height = 200
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
paint.color = Color.WHITE
paint.style = Paint.Style.FILL
paint.textSize = 64f
canvas.drawText(text, 0f, 60f, paint)
val rectParams = RectParams().apply {
setCoordinates(
25f /* x position */,
25f, /* y position */
bitmap.width.toFloat(),
bitmap.height.toFloat(),
0.8f, /* scale */
0f /* rotation */
)
}
val textEffect = VisualTimedEffect(
effectDrawable = VideoEffectsHelper.createTextEffect(
UUID.randomUUID(),
bitmap,
rectParams
)
)Apply blur mask:
val (width, height) = viewportSize.width to viewportSize.height
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8)
val canvas = Canvas(bitmap)
val paint = Paint()
paint.color = Color.WHITE
canvas.drawCircle(width / 2.0f, height / 2.0f, height / 5.0f, paint)
val blurEffect = VisualTimedEffect(effectDrawable = BlurEffectDrawable(bitmap))Requires Face AR SDK:
Dependencies:
implementation "com.banuba.sdk:effect-player-adapter:${banubaSdkVersion}"Module setup:
// Include BanubaEffectPlayerKoinModule in your Koin modules listApply AR effect:
val preparedMaskEffect = BanubaEffectHelper(context).prepareEffect(effectName)
val maskEffect = VisualTimedEffect(
effectDrawable = VideoEffectsHelper.createMaskEffect(preparedMaskEffect.uri)
)By default, effects apply to entire video. Customize using timing parameters:
class VisualTimedEffect(
effectDrawable: VisualEffectDrawable,
startTimeBundle: TimeBundle = TimeBundle(0, 0),
startTotal: Int = 0,
endTimeBundle: TimeBundle = TimeBundle(Int.MAX_VALUE, Int.MAX_VALUE),
endTotal: Int = Int.MAX_VALUE
) : TypedTimedEffect<VisualEffectDrawable>
class SpeedTimedEffect(
effectDrawable: SpeedEffectDrawable,
startTimeBundle: TimeBundle = TimeBundle(0, 0),
startTotal: Int = 0,
endTimeBundle: TimeBundle = TimeBundle(0, Int.MAX_VALUE),
endTotal: Int = Int.MAX_VALUE
) : TypedTimedEffect<SpeedEffectDrawable>Use these parameters to control when effects start and end during playback.