This commit is contained in:
youngq 2024-12-09 20:28:37 +08:00
parent 0736345acd
commit ee2a75ba8d
8 changed files with 124 additions and 24 deletions

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Demo.Common.Converters
{
public class VolumeToScaleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null && double.TryParse(value.ToString(), out double volume))
{
return Math.Max(0, Math.Min(1, volume / 255.0));
}
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -11,7 +11,7 @@ namespace Demo.Common.Helpers
{
public class AgoraHelper : IRtcEngineEventHandler
{
private static uint _localUId;
public static uint _localUId;
public static IRtcEngine _RtcEngineInstance;
public static int Init(string appId, uint localUid = 0)
{
@ -26,6 +26,8 @@ namespace Demo.Common.Helpers
ret = _RtcEngineInstance.InitEventHandler(new RtcEngineEventHandler());
_localUId = localUid;
_RtcEngineInstance.EnableAudioVolumeIndication(200, 3, false);
return ret;
}

View File

@ -50,8 +50,18 @@ namespace Demo.Common.Helpers
public override void OnAudioVolumeIndication(RtcConnection connection, AudioVolumeInfo[] speakers, uint speakerNumber, int totalVolume)
{
if (speakers.Length <= 0)
{
return;
}
speakers.ForEach(sp =>
{
sp.uid = sp.uid == 0 ? AgoraHelper._localUId : sp.uid;
aggregator.GetEvent<AudioVolumeIndicationEvent>().Publish(sp);
});
//aggregator.GetEvent<AudioVolumeIndicationEvent>().Publish();
}
}

View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1733741697356" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="17185" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M555.314561 942.368764v81.631236H468.685494v-81.631236A416.985683 416.985683 0 0 1 95.514128 526.993492V347.071584h85.518438v179.921908a330.967462 330.967462 0 0 0 661.934924 0V347.071584H928.485928v179.921908a416.985683 416.985683 0 0 1-373.171367 415.375272zM514.221286 0a248.114534 248.114534 0 0 1 248.225596 248.225597v277.657266a248.225597 248.225597 0 1 1-496.451193 0v-277.657266A248.114534 248.114534 0 0 1 514.221286 0z" fill="#dbdbdb" p-id="17186"></path></svg>

After

Width:  |  Height:  |  Size: 806 B

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<UseWindowsForms>True</UseWindowsForms>
@ -28,5 +28,6 @@
<Resource Include="Assets\more.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\mico.svg" />
</ItemGroup>
</Project>

View File

@ -18,9 +18,13 @@ namespace Meeting.V2.Demo.ViewModels
private VideoView _view;
public VideoViewModel()
public VideoViewModel(IEventAggregator aggregator)
{
//aggregator.GetEvent<UserJoinEvent>().Subscribe(RenderVideoView);
aggregator.GetEvent<AudioVolumeIndicationEvent>().Subscribe(SetUserVolume,
arg =>
{
return UserInfo != null && UserInfo.Id > 0 && arg.uid > 0 && arg.uid == UserInfo.Id;
});
}
public DelegateCommand<VideoView> LoadedCommand => new DelegateCommand<VideoView>((u) =>
@ -51,6 +55,24 @@ namespace Meeting.V2.Demo.ViewModels
}
}
private uint microphoneVolume;
/// <summary>
/// 用户麦克风音量
/// </summary>
public uint MicrophoneVolume
{
get { return microphoneVolume; }
set { SetProperty(ref microphoneVolume, value); }
}
private void SetUserVolume(AudioVolumeInfo volumeInfo)
{
MicrophoneVolume = volumeInfo.volume;
}
public DelegateCommand OperClickCommand => new DelegateCommand(() =>

View File

@ -29,6 +29,7 @@
<UserControl.Resources>
<cnt:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<cnt:AspectRatioConverter x:Key="AspectRatioConverter" />
<cnt:VolumeToScaleConverter x:Key="VolumeToScaleConverter" />
</UserControl.Resources>
<Grid>
@ -42,8 +43,8 @@
x:Name="pic_frame"
BackColor="#000000"
Dock="Fill"
MouseEnter="pic_frame_MouseEnter"
MouseDoubleClick="pic_frame_MouseDoubleClick"
MouseEnter="pic_frame_MouseEnter"
MouseLeave="pic_frame_MouseLeave"
SizeMode="StretchImage" />
</WindowsFormsHost>
@ -75,18 +76,52 @@
<svgc:SvgViewbox
x:Name="icon_manager"
Margin="3"
MessageFillBrush="red"
Source="Assets/manager.svg" />
</Border>
<Border Background="#8C000000" CornerRadius="0,8,0,0">
<TextBlock
x:Name="txt_uname"
Margin="5"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="12"
Foreground="White"
Text="{Binding UserInfo.UserName, Mode=TwoWay}" />
<DockPanel>
<Grid>
<!-- 原始的SVG图标 -->
<svgc:SvgViewbox
x:Name="icon_mic"
Margin="3"
Source="Assets/mico.svg" />
<!-- 音量进度条 -->
<Rectangle
Width="7"
Height="12"
Margin="0,-4,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="#36B282"
RadiusX="3.5"
RadiusY="3.5"
RenderTransformOrigin="0.5,1">
<Rectangle.RenderTransform>
<ScaleTransform>
<ScaleTransform.ScaleY>
<Binding
Converter="{StaticResource VolumeToScaleConverter}"
Mode="OneWay"
NotifyOnTargetUpdated="True"
Path="MicrophoneVolume" />
</ScaleTransform.ScaleY>
</ScaleTransform>
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
<TextBlock
x:Name="txt_uname"
Margin="5"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="12"
Foreground="White"
Text="{Binding UserInfo.UserName, Mode=TwoWay}" />
</DockPanel>
</Border>
</StackPanel>
<!--#endregion-->

View File

@ -34,7 +34,7 @@ namespace Meeting.V2.Demo.Views
private static void OnUserInfoPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is VideoView videoView )
if (d is VideoView videoView)
{
var viewDataContext = videoView.DataContext as VideoViewModel;
viewDataContext.UserInfo = e.NewValue as User;
@ -52,6 +52,7 @@ namespace Meeting.V2.Demo.Views
private void pic_frame_MouseEnter(object sender, EventArgs e)
{
btn_oper.Visibility = Visibility.Visible;
}
private async void pic_frame_MouseLeave(object sender, EventArgs e)
@ -79,10 +80,11 @@ namespace Meeting.V2.Demo.Views
private async void btn_oper_MouseLeave(object sender, MouseEventArgs e)
{
await Task.Delay(50).ConfigureAwait(false);
//await Task.Delay(50).ConfigureAwait(false);
IsOperVisible = false;
}
#endregion