Why do real-time volume adjustment
RTMP or RTSP live broadcast playback volume adjustment is mainly used for multi-instance (multi-window) playback scenarios, such as playing four RTMP or RTSP streams at the same time. If all audio channels are open and several audio channels are open at the same time, user experience may be affected. Our general practice is to support real-time mute of the player end. A more granular approach is to adjust the volume of each RTMP/RTSP stream in real time.
Volume control interface design
The volume adjustment function of RTMP or RTSP live broadcast player is designed to be aligned with the functions of common local players or on-demand players (such as VLC and PotPlayer). The volume can be adjusted in real time. This paper takes the Windows platform RTSP live broadcast SDK/RTMP live broadcast SDK’s C++ interface demo as an example (C# is also available, please refer to Github for details) to briefly introduce the relevant interface design and usage.
/* Sets the playback volume. The range is [0, 100], where 0 is mute, 100 is maximum volume, and the default is 100
NT_UINT32(NT_API *SetAudioVolume)(NT_HANDLE handle, NT_INT32 volume);
Copy the code
Specific call:
C++ demo uses the CSliderCtrl control as an example. Set the volume adjustment intensity to [0, 100]. When set to 0, mute in real time.
CSliderCtrl slider_audio_volume_;
player_api_.SetAudioVolume(player_handle_, slider_audio_volume_.GetPos());
Copy the code
void CSmartPlayerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
if (IDC_SLIDER_VOLUME == pScrollBar->GetDlgCtrlID())
{
switch (nSBCode)
{
case SB_LINELEFT:
case SB_LINERIGHT:
case SB_PAGELEFT:
case SB_PAGERIGHT:
case SB_LEFT:
case SB_RIGHT:
{
/*std::wostringstream wss; wss << L"OnHScroll nSBCode:" << nSBCode << " nPos:" << nPos << " GetPos():" << slider_audio_device_volume_.GetPos() << "\r\n"; OutputDebugString(wss.str().c_str()); * /
if(is_playing_ && player_handle_ ! =NULL)
{
player_api_.SetAudioVolume(player_handle_, slider_audio_volume_.GetPos()); }}break;
case SB_THUMBPOSITION:
{
/*std::wostringstream wss; wss << L"SB_THUMBPOSITION" << " nPos:" << nPos << " GetPos():" << slider_audio_device_volume_.GetPos() << "\r\n"; OutputDebugString(wss.str().c_str()); * /
}
break;
case SB_THUMBTRACK:
{
/*std::wostringstream wss; wss << L"SB_THUMBTRACK" << " nPos:" << nPos << " GetPos():" << slider_audio_device_volume_.GetPos() << "\r\n"; OutputDebugString(wss.str().c_str()); * /
if(is_playing_ && player_handle_ ! =NULL)
{
player_api_.SetAudioVolume(player_handle_, slider_audio_volume_.GetPos()); }}break;
default:
break;
}
}
CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}
Copy the code
Real-time volume adjustment, as an extension of the RTSP or RTMP live player, is useful in many industries, such as education, monitoring and multi-window (large screen environment) playback scenarios, and interested developers can try it out.