tencent cloud

User Generated Short Video SDK

iOS

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

Feature Overview

Through BGM-related interfaces, you can add background audio/music to short videos. This document describes BGM management features, including adding, removing, adjusting position, volume, playback speed, and playback range.

Related Interface Classes

Interface Class Name
Description
TAVEditor
SDK operation entry class.

Background Music Methods

Add Background Music

// Add background music
/// - Parameters:
/// - bgmPath: File path of the music asset
/// - startAtVideoTime: The time on the timeline when BGM starts playing (default is 0). For example, if the main track is a 10s video and you want BGM to start at the 5th second, pass the CMTime corresponding to 5s
/// - timeRange: Playback range to trim from the music asset (default is the entire track). For example, if a song is 0-90s, you can set timeRange to trim any segment within 0-90s
/// - return: Unique ID of the BGM asset
- (int)addBgm:(NSString *)bgmPath startAtVideoTime:(CMTime)startAtVideoTime timeRange:(CMTimeRange)timeRange;

Remove Background Music

/// Remove background music by unique ID
/// - Parameter bgmId: ID generated when adding background music
- (BOOL)removeBgm:(int)bgmId;

/// Remove all BGMs
- (void)removeAllBgm;

Adjust BGM Start Time in Video

/// Adjust the BGM start position in the video. This feature is not yet active
/// - Parameters:
/// - bgmId: ID generated when adding background music
/// - startAtVideoTime: The time on the timeline when BGM starts playing. For example, if the main track is a 10s video and you want BGM to start at the 5th second, pass the CMTime corresponding to 5s
- (void)updateBgm:(int)bgmId atVideoTime:(CMTime)startAtVideoTime;

Adjust BGM Playback Range

/// Set BGM playback range
/// - Parameters:
/// - bgmId: ID generated when adding background music
/// - timeRange: Playback range to trim from the music asset (default is the entire track). For example, if a song is 0-90s, you can set timeRange to trim any segment within 0-90s
- (void)updateBgm:(int)bgmId playRange:(CMTimeRange)timeRange;

Adjust BGM Volume

/// Set BGM playback volume
/// - Parameters:
/// - bgmId: ID generated when adding background music
/// - volume: Volume (0-1f)
- (void)setBgm:(int)bgmId volume:(float)volume;

/// Set volume for all background music
/// - Parameters:
/// - volume: Volume (0-1f)
- (void)setAllBgmVolume:(float)volume;

/// Get BGM volume
/// - Parameters:
/// - bgmId: ID generated when adding background music
/// - return: Volume
- (float)getBgmVolume:(int)bgmId;


Adjust BGM Speed

/// Adjust BGM playback speed
/// - Parameters:
/// - bgmId: ID generated when adding background music
/// - speed: Playback speed. 1 = normal, >1 = fast, <1 = slow
- (void)setBgm:(int)bgmId speed:(float)speed;

/// Get BGM playback speed
/// - Parameters:
/// - bgmID: ID generated when adding background music
/// - return: Current BGM playback speed
- (float)getBgmSpeed:(int)bgmId;


ヘルプとサポート

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

フィードバック