In the lyrics synchronization solution, the actions of the three different roles are as follows:
Main Singer
Chorus
Audience
NTP time calibration
Enable black frame insertion
Send SEI messages
Local lyrics synchronization
Update lyrics control
NTP time calibration
Local lyrics synchronization
Update lyrics control
NTP time calibration
Receive SEI messages
Update lyrics control
Among them, the main singer and chorus update the lyrics progress locally based on the synchronized song playback progress; the audience end needs to receive SEI messages containing the latest lyrics progress sent by the main singer end to update the local lyrics progress.
Timing diagram
The synchronization of lyrics timing can mainly be divided into three parts: NTP time synchronization, enabling black frame compensation, and local and remote lyrics synchronization. The code implementation of NTP time synchronization has been provided in the Song Synchronization document. The following will provide specific code implementation for the latter two parts.
Key code implementation
1. Enable Black Frame Insertion
// In pure audio mode, the main instance (vocal instance)
// needs to enable black frame padding to carry SEI messages.
The frequency at which the lead singer sends SEI messages is determined by the frequency of background music playback event callbacks, which is usually 200ms;
The reason for not directly using CMD messages to send song progress is that the signaling transmitted through the SEI channel can be transmitted with the video frame to the live CDN, which has better compatibility for viewers who pull the CDN stream.
// Determine whether it is necessary to seek the lyrics control
// based on the received latest progress and the error of the local lyrics progress.
...
}
Note
If reusing the TUIKaraoke component's lyric control, please refer to the code logic in the TUIKaraoke TRTCLyricView section to synchronize the progress of the lyric control.