正常直播

This commit is contained in:
lxmou666 2020-12-28 23:38:39 +08:00
parent c09f307a79
commit 7c87c4fb30
5 changed files with 274 additions and 89 deletions

View File

@ -40,6 +40,7 @@ namespace JianGongYun.TRTC
/// 直播窗口
/// </summary>
public static Window CurrentLiveWindow;
private static LiveWindowViewModel liveWinMode;
public static ClassroomEntity CurrentClassroomEntity { get; private set; }
//public static int UserCount = 999;
/// <summary>
@ -58,6 +59,7 @@ namespace JianGongYun.TRTC
CallerWindow = callerWindow;
CurrentClassroomEntity = classroomEntity;
CurrentLiveWindow = new LiveWindow();
liveWinMode = CurrentLiveWindow.DataContext as LiveWindowViewModel;
CurrentLiveWindow.Closed += CurrentLiveWindow_Closed;
lTRTCCloud = ITRTCCloud.getTRTCShareInstance();//创建TRTC实例
@ -99,6 +101,8 @@ namespace JianGongYun.TRTC
lTRTCCloud.setLocalRenderParams(ref renderParams);
//设备完结
//liveWinMode.LoadAllScreen();
callerWindow.Hide();//隐藏调用窗口
CurrentLiveWindow.Show();
}
@ -117,7 +121,6 @@ namespace JianGongYun.TRTC
/// <param name="parent">视频容器</param>
public static void StartVideoMain(Panel parent)
{
var liveWinMode = CurrentLiveWindow.DataContext as LiveWindowViewModel;
if (!liveWinMode.CameraRunning)
{
lTRTCCloud.startLocalPreview(IntPtr.Zero);
@ -126,13 +129,21 @@ namespace JianGongYun.TRTC
}
}
public static void ResizeVideoMain(Panel parent)
{
if (liveWinMode.CameraRunning)
{
StopVideoMain(parent);
StartVideoMain(parent);
}
}
/// <summary>
/// 停止摄像头
/// </summary>
/// <param name="parent"></param>
public static void StopVideoMain(Panel parent)
{
var liveWinMode = CurrentLiveWindow.DataContext as LiveWindowViewModel;
if (liveWinMode.CameraRunning)
{
liveWinMode.CameraRunning = false;
@ -147,7 +158,6 @@ namespace JianGongYun.TRTC
/// <param name="parent"></param>
public static void StartVideoSub(Panel parent)
{
var liveWinMode = CurrentLiveWindow.DataContext as LiveWindowViewModel;
if (!liveWinMode.ScreenRunning)
{
liveWinMode.ScreenRunning = true;
@ -156,13 +166,20 @@ namespace JianGongYun.TRTC
AddCustomVideoView(parent, CurrentClassroomEntity.TeacherId, TRTCVideoStreamType.TRTCVideoStreamTypeSub, true);
}
}
public static void ResizeVideoSub(Panel parent)
{
if (liveWinMode.ScreenRunning)
{
RemoveCustomVideoView(parent, CurrentClassroomEntity.TeacherId, TRTCVideoStreamType.TRTCVideoStreamTypeSub, true);
AddCustomVideoView(parent, CurrentClassroomEntity.TeacherId, TRTCVideoStreamType.TRTCVideoStreamTypeSub, true);
}
}
/// <summary>
/// 停止屏幕分享
/// </summary>
/// <param name="parent"></param>
public static void StopVideoSub(Panel parent)
{
var liveWinMode = CurrentLiveWindow.DataContext as LiveWindowViewModel;
if (liveWinMode.ScreenRunning)
{
liveWinMode.ScreenRunning = false;
@ -176,13 +193,46 @@ namespace JianGongYun.TRTC
/// </summary>
public static void SelectVieoSub()
{
var liveWinMode = CurrentLiveWindow.DataContext as LiveWindowViewModel;
var current = liveWinMode.CurrentShareScreen;
var rect = new RECT();
var property = new TRTCScreenCaptureProperty();
lTRTCCloud.selectScreenCaptureTarget(ref current, ref rect, ref property);
}
/// <summary>
/// 启动麦克风
/// </summary>
public static void StartMic()
{
if (!liveWinMode.MicRunning)
{
liveWinMode.MicRunning = true;
lTRTCCloud.startLocalAudio(settingWindowViewModel.LiveAudioLevel);
}
}
/// <summary>
/// 关闭麦克风
/// </summary>
public static void StopMic()
{
if (liveWinMode.MicRunning)
{
liveWinMode.MicRunning = false;
lTRTCCloud.stopLocalAudio();
}
}
/// <summary>
/// 设置麦克风静音
/// </summary>
public static void SetMicMute(bool? mute = true)
{
if (liveWinMode.MicRunning)
{
liveWinMode.MicMute = mute.HasValue ? mute.Value : !liveWinMode.MicMute;
lTRTCCloud.muteLocalAudio(liveWinMode.MicMute);
}
}
/// <summary>
/// 添加自定义渲染 View 并绑定渲染回调
/// </summary>
@ -190,10 +240,11 @@ namespace JianGongYun.TRTC
{
TXLiteAVVideoView videoView = new TXLiteAVVideoView();
videoView.RegEngine(userId, streamType, lTRTCCloud, local);
videoView.SetRenderMode(settingWindowViewModel.RenderParams.fillMode);
videoView.SetRenderMode(streamType == TRTCVideoStreamType.TRTCVideoStreamTypeBig ? settingWindowViewModel.RenderParams.fillMode : TRTCVideoFillMode.TRTCVideoFillMode_Fit);
videoView.Width = parent.ActualWidth;
videoView.Height = parent.ActualHeight;
parent.Dispatcher.Invoke(new Action(() => {
parent.Dispatcher.Invoke(new Action(() =>
{
parent.Children.Add(videoView);
}));
string key = string.Format("{0}_{1}", userId, streamType);
@ -210,7 +261,8 @@ namespace JianGongYun.TRTC
if (VideoViews.TryGetValue(key, out videoView))
{
videoView.RemoveEngine(lTRTCCloud);
parent.Dispatcher.Invoke(new Action(() => {
parent.Dispatcher.Invoke(new Action(() =>
{
parent.Children.Remove(videoView);
}));
VideoViews.Remove(key);

View File

@ -177,12 +177,28 @@ namespace JianGongYun.TRTC.ViewModels
return _MicRunning;
}
}
/// <summary>
/// 麦克风静音
/// </summary>
private bool _MicMute = false;
public bool MicMute
{
set
{
_MicMute = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("MicMute"));
}
}
get
{
return _MicMute;
}
}
static object ScreenListLock = new object();
private SIZE thumbSize = new SIZE { cx = 300, cy = 200 };
private SIZE iconSize = new SIZE { cx = 50, cy = 50 };
private ObservableCollection<TRTCScreenEntity> _LiveScreens;
private ObservableCollection<TRTCScreenEntity> _LiveScreens = new ObservableCollection<TRTCScreenEntity>();
/// <summary>
/// 可分享桌面
/// </summary>
@ -190,24 +206,38 @@ namespace JianGongYun.TRTC.ViewModels
{
get
{
lock (ScreenListLock)
{
_LiveScreens.Clear();
var temp = LiveClassroom.lTRTCCloud.getScreenCaptureSources(ref thumbSize, ref iconSize);
var count = temp.getCount();
for (uint i = 0; i < count; i++)
{
var info = temp.getSourceInfo(i);
//var icon = Util.ToWriteableBitmap(ref info.iconBGRA);
var thumb = info.thumbBGRA.ToWriteableBitmap();
_LiveScreens.Add(new TRTCScreenEntity { SourceId = info.sourceId, SourceName = info.sourceName, Type = info.type, Thumb = thumb, Info = info });
}
temp.release();
}
return _LiveScreens;
}
}
static object ScreenListLock = new object();
private SIZE thumbSize = new SIZE { cx = 300, cy = 200 };
private SIZE iconSize = new SIZE { cx = 50, cy = 50 };
/// <summary>
/// 获取所有桌面列表
/// </summary>
public void LoadAllScreen()
{
lock (ScreenListLock)
{
Console.WriteLine("get LiveScreens");
_LiveScreens.Clear();
Console.WriteLine("get LiveScreens Clear");
var temp = LiveClassroom.lTRTCCloud.getScreenCaptureSources(ref thumbSize, ref iconSize);
var count = temp.getCount();
Console.WriteLine($"get LiveScreens {count}");
for (uint i = 0; i < count; i++)
{
var info = temp.getSourceInfo(i);
//var icon = Util.ToWriteableBitmap(ref info.iconBGRA);
Console.WriteLine($"get LiveScreens {i} {info.sourceId}");
var thumb = info.thumbBGRA.ToWriteableBitmap();
_LiveScreens.Add(new TRTCScreenEntity { SourceId = info.sourceId, SourceName = info.sourceName, Type = info.type, Thumb = thumb, Info = info });
}
temp.release();
}
}
/// <summary>
/// 当前分享的桌面列表

View File

@ -616,7 +616,7 @@ namespace JianGongYun.TRTC.ViewModels
{
get
{
return new TRTCVideoEncParam { enableAdjustRes = true, resMode = TRTCVideoResolutionMode.TRTCVideoResolutionModeLandscape, videoBitrate = LiveMainBitrate, videoFps = LiveMainFps };
return new TRTCVideoEncParam { enableAdjustRes = false, resMode = TRTCVideoResolutionMode.TRTCVideoResolutionModeLandscape, videoBitrate = LiveMainBitrate, videoFps = LiveMainFps };
}
}
public TRTCNetworkQosParam QosParams

View File

@ -19,6 +19,8 @@
<Geometry x:Key="Icon_Screen">M864 159.872L160 160c-17.696 0-32 14.176-32 31.872v448a32 32 0 0 0 32 32h704a32 32 0 0 0 32-32v-448a32 32 0 0 0-32-32zM864 640H160V191.872h704V640z M928 32H96a96 96 0 0 0-96 96v640a95.904 95.904 0 0 0 95.68 95.936H416v38.944l-199.744 25.952A31.968 31.968 0 0 0 224 991.872h576a32 32 0 0 0 7.744-63.072L608 902.88v-38.944h320.32A95.904 95.904 0 0 0 1024 768V128a96 96 0 0 0-96-96z m32 736c0 17.632-14.368 32-32 32H96c-17.664 0-32-14.368-32-32V128a32 32 0 0 1 32-32h832c17.632 0 32 14.336 32 32v640z</Geometry>
<Geometry x:Key="Icon_Mic">M486.4 972.8v-128.9728A332.8 332.8 0 0 1 179.2 512a25.6 25.6 0 0 1 51.2 0 281.6 281.6 0 0 0 563.2 0 25.6 25.6 0 1 1 51.2 0 332.8 332.8 0 0 1-307.2 331.8272V972.8h153.6a25.6 25.6 0 1 1 0 51.2h-358.4a25.6 25.6 0 1 1 0-51.2h153.6zM512 51.2a153.6 153.6 0 0 0-153.6 153.6v307.2a153.6 153.6 0 0 0 307.2 0V204.8a153.6 153.6 0 0 0-153.6-153.6z m0-51.2a204.8 204.8 0 0 1 204.8 204.8v307.2a204.8 204.8 0 1 1-409.6 0V204.8a204.8 204.8 0 0 1 204.8-204.8z</Geometry>
<Geometry x:Key="Icon_User">M511.626 1.896C229.572 1.896 0.927 230.541 0.927 512.595c0 282.055 228.645 510.699 510.699 510.699s510.698-228.645 510.698-510.699S793.68 1.896 511.626 1.896z m0 69.641c243.606 0 441.058 197.474 441.058 441.058 0 87.347-25.392 168.762-69.194 237.271-73.419-77.609-170.944-132.204-280.597-151.829 70.004-33.755 118.404-105.164 118.404-188.066 0-115.388-93.535-208.922-208.923-208.922S303.452 294.583 303.452 409.97c0 82.902 48.399 154.311 118.403 188.066-110.093 19.704-207.96 74.661-281.479 152.77-44.177-68.704-69.808-150.465-69.808-238.211 0-243.584 197.496-441.058 441.058-441.058z</Geometry>
<Geometry x:Key="Icon_ChangeScreen">M447.5904 819.1488H166.4a89.6 89.6 0 0 1-89.6-89.4976V166.4c0-49.3568 40.192-89.5488 89.6-89.5488h563.2c49.4592 0 89.6512 40.192 89.6512 89.5488v281.6H896v-281.6A166.5536 166.5536 0 0 0 729.6 0h-563.2A166.5536 166.5536 0 0 0 0 166.4v563.2512A166.656 166.656 0 0 0 166.4 896h281.1904v-76.8512z M947.2 238.5408V857.6c0 49.408-40.192 89.6-89.6 89.6H242.7904V1024H857.6A166.6048 166.6048 0 0 0 1024 857.6V238.5408h-76.8z M577.8944 813.8752h235.9808v-236.032h-76.8v104.96l-395.776-395.8784h104.9088V210.176H210.1248v235.9808h76.8V341.248l395.9296 395.8784h-104.96z</Geometry>
<Geometry x:Key="Icon_Ban">M2.896 921.614L924.656 0l102.385 102.386L105.354 1024z</Geometry>
<BooleanToVisibilityConverter x:Key="VisibilityOfBool" />
<live:UnBooleanToVisibilityConverter x:Key="UnVisibilityOfBool" />
<!--直播方式数据类型转换-->
@ -73,76 +75,105 @@
<Button Click="Setting_Btn_Click" Style="{StaticResource CusIconBtn}" Canvas.Left="27" Canvas.Top="15" Background="Transparent" BorderThickness="0">
<Button.Content>
<StackPanel>
<Path Width="18" Height="18" Fill="#fff" Shape.Stretch="Fill" Data="{StaticResource Icon_Setting}" />
<TextBlock Foreground="#fff" Margin="0 3 0 0">设置</TextBlock>
<Path Width="18" Height="18" Fill="#aaaaaa" Shape.Stretch="Fill" Data="{StaticResource Icon_Setting}" />
<TextBlock Foreground="#aaaaaa" Margin="0 3 0 0">设置</TextBlock>
</StackPanel>
</Button.Content>
</Button>
<StackPanel Visibility="{Binding IsLive, Converter={StaticResource VisibilityOfBool}}" Orientation="Horizontal" Canvas.Right="27" Canvas.Top="10" Height="50">
<Canvas HorizontalAlignment="Right" Height="50" Width="50">
<Metro:AduSysButton ToolTip="禁用/启用麦克风静音" Foreground="#aaaaaa" IconHeight="25" IconWidth="18" CornerRadius="6" Height="50" Width="50" Icon="{StaticResource Icon_Mic}" Content="" />
<Metro:AduSysButton ToolTip="禁用/启用麦克风静音" Visibility="{Binding MicMute, Converter={StaticResource VisibilityOfBool}}" Foreground="#aaaaaa" IconHeight="25" IconWidth="25" CornerRadius="6" Height="50" Width="50" Icon="{StaticResource Icon_Ban}" Content="" />
</Canvas>
<Canvas HorizontalAlignment="Right" Height="50" Width="50">
<Metro:AduSysButton ToolTip="禁用/启用摄像头" Foreground="#aaaaaa" IconHeight="25" IconWidth="20" CornerRadius="6" Height="50" Width="50" Icon="{StaticResource Icon_Camera}" Content="" />
<Metro:AduSysButton ToolTip="禁用/启用摄像头" Visibility="{Binding CameraRunning, Converter={StaticResource UnVisibilityOfBool}}" Foreground="#aaaaaa" IconHeight="25" IconWidth="25" CornerRadius="6" Height="50" Width="50" Icon="{StaticResource Icon_Ban}" Content="" />
</Canvas>
<Canvas HorizontalAlignment="Right" Height="50" Width="50">
<Metro:AduSysButton ToolTip="禁用/启用桌面分享" Foreground="#aaaaaa" IconHeight="25" IconWidth="24" CornerRadius="6" Height="50" Width="50" Icon="{StaticResource Icon_Screen}" Content="" />
<Metro:AduSysButton ToolTip="禁用/启用桌面分享" Visibility="{Binding ScreenRunning, Converter={StaticResource UnVisibilityOfBool}}" Foreground="#aaaaaa" IconHeight="25" IconWidth="25" CornerRadius="6" Height="50" Width="50" Icon="{StaticResource Icon_Ban}" Content="" />
</Canvas>
<Canvas HorizontalAlignment="Right" Height="50" Width="50">
<Metro:AduSysButton Click="ChangeWin_Click" ToolTip="切换分享窗口" Foreground="#aaaaaa" IconHeight="25" IconWidth="24" CornerRadius="6" Height="50" Width="50" Icon="{StaticResource Icon_ChangeScreen}" Content="" />
</Canvas>
</StackPanel>
</Canvas>
<!--中间面板-->
<Canvas x:Name="CusContent" Background="#151618">
<!--屏幕预览容器-->
<Grid x:Name="BeforeLiveSubViewWrap" Width="{Binding ElementName=CusContent,Path=ActualWidth}" Height="{Binding ElementName=CusContent,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0"></Grid>
<!--直播前-->
<Grid Canvas.Top="0" Canvas.Left="0" Background="#aa151618" Height="{Binding ElementName=CusContent,Path=ActualHeight}" Width="{Binding ElementName=CusContent,Path=ActualWidth}" Visibility="{Binding IsLive, Converter={StaticResource UnVisibilityOfBool}}">
<StackPanel Width="700" VerticalAlignment="Center">
<TextBlock FontSize="30" Foreground="#999999" HorizontalAlignment="Center">请选择授课方式</TextBlock>
<TextBlock HorizontalAlignment="Center" FontSize="16" Margin="0 10 0 0" Foreground="#999999">您可在上课期间随时调整授课方式</TextBlock>
<Grid Margin="0 30 0 0" Height="300">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Margin="5" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="2" Background="#2f3035">
<Canvas x:Name="CameraPrew">
<Grid Width="{Binding ElementName=CameraPrew,Path=ActualWidth}" Height="{Binding ElementName=CameraPrew,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0">
<Path Margin="0 0 0 30" Width="111" Height="111" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_User}" />
<Canvas x:Name="BeforeLivePanel">
<!--屏幕预览容器-->
<Grid x:Name="BeforeLiveSubViewWrap" Width="{Binding ElementName=BeforeLivePanel,Path=ActualWidth}" Height="{Binding ElementName=BeforeLivePanel,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0"></Grid>
<!--标题和直播类型选项-->
<Grid Width="{Binding ElementName=BeforeLivePanel,Path=ActualWidth}" Height="{Binding ElementName=BeforeLivePanel,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0">
<StackPanel Width="700" VerticalAlignment="Center">
<TextBlock FontSize="30" Foreground="#999999" HorizontalAlignment="Center">请选择授课方式</TextBlock>
<TextBlock HorizontalAlignment="Center" FontSize="16" Margin="0 10 0 0" Foreground="#999999">您可在上课期间随时调整授课方式</TextBlock>
<Grid Margin="0 30 0 0" Height="300">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Margin="5" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="2" Background="#2f3035">
<Canvas x:Name="CameraPrew">
<Grid Width="{Binding ElementName=CameraPrew,Path=ActualWidth}" Height="{Binding ElementName=CameraPrew,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0">
<Path Margin="0 0 0 30" Width="111" Height="111" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_User}" />
</Grid>
<!--摄像头预览容器-->
<Grid x:Name="BeforeLiveViewWrap" Width="{Binding ElementName=CameraPrew,Path=ActualWidth}" Height="{Binding ElementName=CameraPrew,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0"></Grid>
<TextBlock Width="{Binding ElementName=CameraPrew,Path=ActualWidth}" Canvas.Bottom="0" Canvas.Left="0" Padding="5" FontSize="14" Foreground="#cccccc" Background="#65888888" TextAlignment="Center">摄像头预览</TextBlock>
</Canvas>
</Grid>
<!--摄像头预览容器-->
<Grid x:Name="BeforeLiveViewWrap" Width="{Binding ElementName=CameraPrew,Path=ActualWidth}" Height="{Binding ElementName=CameraPrew,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0"></Grid>
<TextBlock Width="{Binding ElementName=CameraPrew,Path=ActualWidth}" Canvas.Bottom="0" Canvas.Left="0" Padding="5" FontSize="14" Foreground="#cccccc" Background="#65888888" TextAlignment="Center">摄像头预览</TextBlock>
</Canvas>
</Grid>
<Grid Margin="5" Background="#2f3035" Grid.Row="0" Grid.Column="2">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<StackPanel Margin="0 0 0 20" HorizontalAlignment="Center" Orientation="Horizontal">
<Path Width="30" Height="35" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_Camera}" />
<TextBlock FontSize="30" Margin="10 0" Foreground="#cccccc">+</TextBlock>
<Path Width="30" Height="30" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_Screen}" />
</StackPanel>
<Metro:AduRadioButton x:Name="Rad1" Click="Tpye_Click" GroupName="LiveType" Foreground="#cccccc" Content="摄像头+屏幕分享" FontSize="14" IconWidth="16" IsChecked="{Binding LiveType,Converter={StaticResource LiveTypeConverter},ConverterParameter=CameraAndScreen}" />
</StackPanel>
</Grid>
<Grid Margin="5" Background="#2f3035" Grid.Row="0" Grid.Column="3">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Path Margin="0 0 0 30" Width="30" Height="30" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_Screen}" />
<Metro:AduRadioButton x:Name="Rad2" Click="Tpye_Click" GroupName="LiveType" Foreground="#cccccc" Content="屏幕分享" FontSize="14" IconWidth="16" IsChecked="{Binding LiveType,Converter={StaticResource LiveTypeConverter},ConverterParameter=OnlyScreen}" />
</StackPanel>
</Grid>
<Grid Margin="5" Background="#2f3035" Grid.Row="1" Grid.Column="2">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Path Margin="0 0 0 25" Width="30" Height="35" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_Camera}" />
<Metro:AduRadioButton x:Name="Rad3" Click="Tpye_Click" GroupName="LiveType" Foreground="#cccccc" Content="摄像头" FontSize="14" IconWidth="16" IsChecked="{Binding LiveType,Converter={StaticResource LiveTypeConverter},ConverterParameter=OnlyCamera}" />
</StackPanel>
</Grid>
<Grid Margin="5" Background="#2f3035" Grid.Row="1" Grid.Column="3">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Path Margin="0 0 0 15" Width="30" Height="45" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_Mic}" />
<Metro:AduRadioButton x:Name="Rad4" Click="Tpye_Click" GroupName="LiveType" Foreground="#cccccc" Content="仅声音" FontSize="14" IconWidth="16" IsChecked="{Binding LiveType,Converter={StaticResource LiveTypeConverter},ConverterParameter=OnlyAudio}" />
</StackPanel>
</Grid>
<Grid Margin="5" Background="#2f3035" Grid.Row="0" Grid.Column="2">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<StackPanel Margin="0 0 0 20" HorizontalAlignment="Center" Orientation="Horizontal">
<Path Width="30" Height="35" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_Camera}" />
<TextBlock FontSize="30" Margin="10 0" Foreground="#cccccc">+</TextBlock>
<Path Width="30" Height="30" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_Screen}" />
</StackPanel>
<Metro:AduRadioButton x:Name="Rad1" Click="Tpye_Click" GroupName="LiveType" Foreground="#cccccc" Content="摄像头+屏幕分享" FontSize="14" IconWidth="16" IsChecked="{Binding LiveType,Converter={StaticResource LiveTypeConverter},ConverterParameter=CameraAndScreen}" />
</StackPanel>
</Grid>
<Grid Margin="5" Background="#2f3035" Grid.Row="0" Grid.Column="3">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Path Margin="0 0 0 30" Width="30" Height="30" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_Screen}" />
<Metro:AduRadioButton x:Name="Rad2" Click="Tpye_Click" GroupName="LiveType" Foreground="#cccccc" Content="屏幕分享" FontSize="14" IconWidth="16" IsChecked="{Binding LiveType,Converter={StaticResource LiveTypeConverter},ConverterParameter=OnlyScreen}" />
</StackPanel>
</Grid>
<Grid Margin="5" Background="#2f3035" Grid.Row="1" Grid.Column="2">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Path Margin="0 0 0 25" Width="30" Height="35" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_Camera}" />
<Metro:AduRadioButton x:Name="Rad3" Click="Tpye_Click" GroupName="LiveType" Foreground="#cccccc" Content="摄像头" FontSize="14" IconWidth="16" IsChecked="{Binding LiveType,Converter={StaticResource LiveTypeConverter},ConverterParameter=OnlyCamera}" />
</StackPanel>
</Grid>
<Grid Margin="5" Background="#2f3035" Grid.Row="1" Grid.Column="3">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Path Margin="0 0 0 15" Width="30" Height="45" Fill="#cccccc" Shape.Stretch="Fill" Data="{StaticResource Icon_Mic}" />
<Metro:AduRadioButton x:Name="Rad4" Click="Tpye_Click" GroupName="LiveType" Foreground="#cccccc" Content="仅声音" FontSize="14" IconWidth="16" IsChecked="{Binding LiveType,Converter={StaticResource LiveTypeConverter},ConverterParameter=OnlyAudio}" />
</StackPanel>
</Grid>
</Grid>
</StackPanel>
</Grid>
</StackPanel>
</Canvas>
</Grid>
<!--直播中-->
<Grid Canvas.Top="0" Canvas.Left="0" Height="{Binding ElementName=CusContent,Path=ActualHeight}" Width="{Binding ElementName=CusContent,Path=ActualWidth}" Visibility="{Binding IsLive, Converter={StaticResource VisibilityOfBool}}">
<TextBlock Foreground="White">true</TextBlock>
<Canvas x:Name="AfterLivePanel">
<!--屏幕预览容器-->
<Grid x:Name="AfterLiveSubViewWrap" Width="{Binding ElementName=AfterLivePanel,Path=ActualWidth}" Height="{Binding ElementName=AfterLivePanel,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0"></Grid>
<!--摄像头预览容器-->
<Border Visibility="{Binding CameraRunning, Converter={StaticResource VisibilityOfBool}}" Width="150" Height="150" BorderThickness="1" BorderBrush="#efefef" Canvas.Bottom="20" Canvas.Right="20">
<Grid x:Name="AfterLiveViewWrap"></Grid>
</Border>
</Canvas>
</Grid>
</Canvas>
</DockPanel>

View File

@ -15,6 +15,7 @@ using System.Linq;
using System.Windows.Threading;
using JianGongYun.TRTC.Components;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace JianGongYun.TRTC.Windows
{
@ -31,13 +32,33 @@ namespace JianGongYun.TRTC.Windows
public LiveWindow()
{
InitializeComponent();
AttachConsole(-1);//把进程挂在控制台,通过命令行启动程序可以看到控制台输出
BeforeLiveSubViewWrap.SizeChanged += BeforeLiveSubViewWrap_SizeChanged;
AfterLiveSubViewWrap.SizeChanged += AfterLiveSubViewWrap_SizeChanged;
//AttachConsole(-1);//把进程挂在控制台,通过命令行启动程序可以看到控制台输出
LiveWindowViewModel = new ViewModels.LiveWindowViewModel();
SettingWindowViewModel = ViewModels.SettingWindowViewModel.GetInstance();
this.DataContext = LiveWindowViewModel;
BorderBrush = new SolidColorBrush(color: Color.FromRgb(42, 43, 48));//窗口标题背景颜色
}
private void AfterLiveSubViewWrap_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (LiveWindowViewModel.IsLive)
{
this.Dispatcher.Invoke(new Action(() => LiveClassroom.ResizeVideoSub(AfterLiveSubViewWrap)));
}
}
private void BeforeLiveSubViewWrap_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (!LiveWindowViewModel.IsLive)
{
this.Dispatcher.Invoke(new Action(() => LiveClassroom.ResizeVideoSub(BeforeLiveSubViewWrap)));
}
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
@ -72,6 +93,21 @@ namespace JianGongYun.TRTC.Windows
base.OnClosed(e);
}
protected override void OnClosing(CancelEventArgs e)
{
LiveClassroom.StopMic();
if (LiveWindowViewModel.IsLive)
{
}
else
{
LiveClassroom.StopVideoMain(BeforeLiveViewWrap);
LiveClassroom.StopVideoSub(BeforeLiveSubViewWrap);
}
base.OnClosing(e);
}
/// <summary>
/// 开始/结束直播
/// </summary>
@ -83,6 +119,11 @@ namespace JianGongYun.TRTC.Windows
var start = Convert.ToBoolean(btn.Tag);
if (start)//开始直播
{
//停止预览
LiveClassroom.StopMic();
LiveClassroom.StopVideoMain(BeforeLiveViewWrap);
LiveClassroom.StopVideoSub(BeforeLiveSubViewWrap);
this.Dispatcher.Invoke(new Action(() =>
{
btn.Type = AduSkin.Controls.FlatButtonSkinEnum.warning;
@ -96,11 +137,28 @@ namespace JianGongYun.TRTC.Windows
btn.Type = AduSkin.Controls.FlatButtonSkinEnum.info;
btn.Content = "开始直播";
}));
//开始直播
if (LiveWindowViewModel.LiveType == Models.LiveTypeEnum.CameraAndScreen || LiveWindowViewModel.LiveType == Models.LiveTypeEnum.OnlyCamera)
{
LiveClassroom.StartVideoMain(AfterLiveViewWrap);
}
if (LiveWindowViewModel.LiveType == Models.LiveTypeEnum.CameraAndScreen || LiveWindowViewModel.LiveType == Models.LiveTypeEnum.OnlyScreen)
{
LiveClassroom.StartVideoSub(AfterLiveSubViewWrap);
}
LiveClassroom.StartMic();
LiveClassroom.SetMicMute(false);
}, SettingWindowViewModel.ScreenRecordingCountdown);
}
else
{
LiveWindowViewModel.IsLive = start;
//停止直播
LiveClassroom.StopMic();
LiveClassroom.StopVideoMain(AfterLiveViewWrap);
LiveClassroom.StopVideoSub(AfterLiveSubViewWrap);
}
}
@ -165,13 +223,15 @@ namespace JianGongYun.TRTC.Windows
switch (LiveWindowViewModel.LiveType)
{
case Models.LiveTypeEnum.CameraAndScreen:
LiveClassroom.StopVideoSub(BeforeLiveSubViewWrap);//停止屏幕分享(二次选择需要先停止分享,不然界面会卡死)
LiveClassroom.StopVideoSub(BeforeLiveSubViewWrap);//停止屏幕分享(直播中SDK再次获取窗口列表会卡死)
LiveWindowViewModel.ShowShareScreenList = true;
this.Dispatcher.Invoke(new Action(() => LiveWindowViewModel.LoadAllScreen()));
break;
case Models.LiveTypeEnum.OnlyScreen:
LiveClassroom.StopVideoSub(BeforeLiveSubViewWrap);//停止屏幕分享(二次选择需要先停止分享,不然界面会卡死)
LiveClassroom.StopVideoSub(BeforeLiveSubViewWrap);//停止屏幕分享(直播中SDK再次获取窗口列表会卡死)
LiveClassroom.StopVideoMain(BeforeLiveViewWrap); //停止摄像头分享
LiveWindowViewModel.ShowShareScreenList = true;
this.Dispatcher.Invoke(new Action(() => LiveWindowViewModel.LoadAllScreen()));
break;
case Models.LiveTypeEnum.OnlyCamera:
LiveClassroom.StopVideoSub(BeforeLiveSubViewWrap);//停止屏幕分享
@ -194,11 +254,23 @@ namespace JianGongYun.TRTC.Windows
private void ShareList_Selected(object sender, RoutedEventArgs e)
{
CloseShareList_Click(sender, e);
LiveClassroom.StartVideoSub(BeforeLiveSubViewWrap);
if (LiveWindowViewModel.LiveType== Models.LiveTypeEnum.CameraAndScreen)
if (LiveWindowViewModel.IsLive && LiveWindowViewModel.ScreenRunning)
{
LiveClassroom.SelectVieoSub();
}
else
{
LiveClassroom.StartVideoSub(BeforeLiveSubViewWrap);
}
if (LiveWindowViewModel.LiveType == Models.LiveTypeEnum.CameraAndScreen)
{
LiveClassroom.StartVideoMain(BeforeLiveViewWrap);
}
}
private void ChangeWin_Click(object sender, RoutedEventArgs e)
{
LiveWindowViewModel.ShowShareScreenList = true;
}
}
}