我们在做Windows平台RTSP、RTMP播放器的时候,有这样的技术需求,特别是多路监控的时候,并不是每一路audio都需要播放出来的,所以,这时候,需要有针对音量调节的设计:
/*
* smart_player_sdk.cs
* Created by daniusdk.com on 2017/04/19.
* WeChat: xinsheng120
*/
/*
* 静音接口,1为静音,0为不静音
*/
[DllImport(@"SmartPlayerSDK.dll")]
public static extern UInt32 NT_SP_SetMute(IntPtr handle, Int32 is_mute);
随着需求越来越多,好多场景下,希望能实时调节播放器的音量,所以,后续我们设计了实时音量调节接口:
/*
* smart_player_sdk.cs
* Created by daniusdk.com on 2017/04/19.
* WeChat: xinsheng120
*/
/*
* 设置播放音量, 范围是[0, 100], 0是静音,100是最大音量, 默认是100
*/
[DllImport(@"SmartPlayerSDK.dll")]
public static extern UInt32 NT_SP_SetAudioVolume(IntPtr handle, Int32 volume);
调用如下,拖动实时音量调节slider即可实现播放音量的动态调整,如果需要实时静音,调整到0,或者是直接SetMute设置0即可。
if (checkBox_mute.Checked)
{
NTSmartPlayerSDK.NT_SP_SetMute(player_handle_, 1);
}
else
{
NTSmartPlayerSDK.NT_SP_SetMute(player_handle_, 0);
}
private void slider_audio_volume_ValueChanged(object sender, EventArgs e)
{
cur_audio_volume.Text = slider_audio_volume.Value.ToString();
if (is_playing_ && player_handle_ != IntPtr.Zero)
{
NTSmartPlayerSDK.NT_SP_SetAudioVolume(player_handle_, slider_audio_volume.Value);
}
}