tencent cloud

User Generated Short Video SDK

Android

Download
フォーカスモード
フォントサイズ
最終更新日: 2026-05-11 17:46:58

Feature Overview

Through the background music (BGM) interfaces, you can insert background audio/music into short videos. This document describes background music management functions, including adding, removing, adjusting position, volume, playback speed, and play range.

Related Interface Classes

Interface Class Name
Description
TAVEditor
SDK operation entry class.

Interface Method Summary

Method
Parameters
Return Value
Description
addBgm(String path, long startAtVideoTimeUS, long startTimeUS, long duration)
path: music file path
startAtVideoTimeUS: start time in the video (us)
startTimeUS: music start time (us)
duration: playback duration (us)
int
Add background music and return an ID
removeBgm(int bgmID)
bgmID: background music ID
boolean
Remove background music
updateBgmPlayOffset(int bgmID, long videoStartTime)
bgmID: background music ID
videoStartTime: video position (us)
void
Adjust background music position in the video
updateBgmPlayRange(int bgmID, long startTime, long duration)
bgmID: background music ID
startTime: start time (us)
duration: playback duration (us)
void
Adjust background music play range
setBgmVolume(int bgmID, float volume)
bgmID: background music ID
volume: volume recommended range 0-3f
void
Set individual background music volume
setAllBgmVolume(float volume)
volume: volume recommended range 0-3f
void
Set all background music volume
getBgmVolume(int bgmID)
bgmID: background music ID
float
Get background music volume
setBgmSpeed(int bgmID, float speed)
bgmID: background music ID
speed: playback speed
void
Set background music playback speed
getBgmSpeed(int bgmID)
bgmID: background music ID
float
Get background music playback speed

Related Methods

Add Background Music

/**
* Add background music
*
* @param path Music file path
* @param startAtVideoTimeUS Time point in the video where background music appears (microseconds)
* @param startTimeUS Start playback time of the background music itself (microseconds)
* @param duration Background music playback duration (microseconds)
* @return Unique background music ID
*/
int bgmId = editor.addBgm(path, startAtVideoTimeUS, startTimeUS, duration);

Remove background music

/**
* Remove background music
*
* @param bgmId Background music ID
* @return Whether deletion was successful
*/
boolean success = editor.removeBgm(bgmId);

Adjust Background Music Position

/**
* Adjust background music position in the video
*
* @param bgmId Background music ID
* @param videoStartTime New video time point (microseconds)
*/
editor.updateBgmPlayOffset(bgmId, videoStartTime);

Adjust background music play range

/**
* Adjust background music play range
*
* @param bgmId Background music ID
* @param startTime New start time (microseconds)
* @param duration New playback duration (microseconds)
*/
editor.updateBgmPlayRange(bgmId, startTime, duration);

Adjust Volume

/**
* Set individual background music volume
*
* @param bgmId Background music ID
* @param volume Volume value, recommended range: 0-3f
*/
editor.setBgmVolume(bgmId, volume);

/**
* Set all background music volume
*
* @param volume Volume value, recommended range: 0-3f
*/
editor.setAllBgmVolume(volume);

/**
* Get background music volume
*
* @param bgmId Background music ID
* @return Current volume value
*/
float volume = editor.getBgmVolume(bgmId);

Adjust Playback Speed

/**
* Set background music playback speed
*
* @param bgmId Background music ID
* @param speed Playback speed (1.0 = normal speed)
*/
editor.setBgmSpeed(bgmId, speed);

/**
* Get background music playback speed
*
* @param bgmId Background music ID
* @return Current playback speed
*/
float speed = editor.getBgmSpeed(bgmId);

Usage Example

// Add background music (starts at 2s in video, plays the first 3s of music, lasts 4s)
int bgmId = editor.addBgm("/sdcard/music.mp3",
2_000_000, // Start time in video
0, // Music start time
4_000_000); // Playback duration

// Adjust volume to 70%
editor.setBgmVolume(bgmId, 0.7f);

// Adjust playback speed to 1.5x
editor.setBgmSpeed(bgmId, 1.5f);

// Start playing music at 5s in the video
editor.updateBgmPlayOffset(bgmId, 5_000_000);

// Adjust music play range (start at 1s, play for 2s)
editor.updateBgmPlayRange(bgmId,
1_000_000, // Start time
2_000_000); // Playback duration

// Remove background music
boolean success = editor.removeBgm(bgmId);

// Get background music volume by ID
float currentVolume = editor.getBgmVolume(bgmId);


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック