diff --git a/JianGongYun/TRTC/LiveClassroom.cs b/JianGongYun/TRTC/LiveClassroom.cs index 0bcc90d..c88b502 100644 --- a/JianGongYun/TRTC/LiveClassroom.cs +++ b/JianGongYun/TRTC/LiveClassroom.cs @@ -82,6 +82,7 @@ namespace JianGongYun.TRTC CurrentLiveWindow.Closed += CurrentLiveWindow_Closed; lTRTCCloud = ITRTCCloud.getTRTCShareInstance();//创建TRTC实例 + lTRTCCloud.addCallback(TRTCCloudCallback);//注册回调 var roomPars = new TRTCParams { sdkAppId = SDKAppID, @@ -116,7 +117,6 @@ namespace JianGongYun.TRTC //liveWinMode.LoadAllScreen(); _RecoderDir = $"{classroomEntity.ClassHead}_{classroomEntity.ClassSubHead}"; - lTRTCCloud.addCallback(TRTCCloudCallback);//注册回调 callerWindow.Hide();//隐藏调用窗口 CurrentLiveWindow.Show(); @@ -371,7 +371,7 @@ namespace JianGongYun.TRTC int runFps = 0;//实时帧 Timer timer = new Timer((a) => { - Debug.Print($"runFps {runFps}. leavingsMat {mats.Count}."); + //Debug.Print($"runFps {runFps}. leavingsMat {mats.Count}."); Interlocked.Exchange(ref runFps, 0); }, null, 0, 1000); @@ -454,7 +454,7 @@ namespace JianGongYun.TRTC } } - Skip1: + Skip1: if (liveWinMode.CameraRunning)//摄像头分享中 { @@ -482,7 +482,7 @@ namespace JianGongYun.TRTC } } - Skip2: + Skip2: mats.Enqueue(BackgroundFrame.CvtColor(ColorConversionCodes.BGRA2BGR)); Interlocked.Increment(ref runFps); @@ -551,14 +551,6 @@ namespace JianGongYun.TRTC Process prc = new Process { StartInfo = new ProcessStartInfo { FileName = Path.Combine(Environment.CurrentDirectory, "ffmpeg.exe"), Arguments = arguments, CreateNoWindow = true, UseShellExecute = false } }; prc.Start(); prc.WaitForExit(); - if (File.Exists(VideoTempPath)) - { - File.Delete(VideoTempPath); - } - if (File.Exists(AudioTempPath)) - { - File.Delete(AudioTempPath); - } CurrentLiveWindow.Dispatcher.Invoke(new Action(() => { NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel() @@ -567,6 +559,27 @@ namespace JianGongYun.TRTC Content = $"成功保存直播视频,路径:{ResultFilePath}。", NotifiactionType = AduSkin.Controls.EnumPromptType.Success }); + var res= AduMessageBox.ShowYesNoCancel("是否删除音视频源文件?", "提醒", "删除", "保留", "浏览"); + if (res== MessageBoxResult.Cancel) + { + var process = new Process + { + StartInfo = new ProcessStartInfo { FileName = "explorer.exe", Arguments = RecoderDir } + }; + process.Start(); + process.WaitForExit(); + } + else if (res== MessageBoxResult.Yes) + { + if (File.Exists(VideoTempPath)) + { + File.Delete(VideoTempPath); + } + if (File.Exists(AudioTempPath)) + { + File.Delete(AudioTempPath); + } + } })); Debug.Print("结束写入视频线程"); }, TaskCreationOptions.LongRunning); diff --git a/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs b/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs index 0340684..5fae0a2 100644 --- a/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs +++ b/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs @@ -27,7 +27,7 @@ namespace JianGongYun.TRTC.ViewModels /// /// 学生总数 /// - private int _StudentCount = 0; + private int _StudentCount = 1; public int StudentCount { set diff --git a/JianGongYun/TRTC/Windows/LiveWindow.xaml b/JianGongYun/TRTC/Windows/LiveWindow.xaml index 3c9560b..8467fc9 100644 --- a/JianGongYun/TRTC/Windows/LiveWindow.xaml +++ b/JianGongYun/TRTC/Windows/LiveWindow.xaml @@ -37,6 +37,12 @@ + + + + + + @@ -58,7 +64,7 @@ - + 直播中 diff --git a/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs b/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs index 5066cfb..7e1cb26 100644 --- a/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs +++ b/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs @@ -27,7 +27,7 @@ namespace JianGongYun.TRTC.Windows [DllImport("Kernel32.dll", EntryPoint = "AttachConsole", CharSet = CharSet.Unicode, SetLastError = true)] public static extern void AttachConsole(int dwProcessId); - ViewModels.LiveWindowViewModel LiveWindowViewModel; + public ViewModels.LiveWindowViewModel LiveWindowViewModel; ViewModels.SettingWindowViewModel SettingWindowViewModel; public LiveWindow() { @@ -344,5 +344,12 @@ namespace JianGongYun.TRTC.Windows Content = $"{(LiveWindowViewModel.ScreenRunning ? "开启" : "关闭")}屏幕分享成功" }); } + + private void PackUp_Click(object sender, RoutedEventArgs e) + { + var blockTop = new LiveWindowTopBlock(this); + this.Hide(); + blockTop.Show(); + } } } diff --git a/JianGongYun/TRTC/Windows/LiveWindowRightBottomBlock.xaml b/JianGongYun/TRTC/Windows/LiveWindowRightBottomBlock.xaml new file mode 100644 index 0000000..703965e --- /dev/null +++ b/JianGongYun/TRTC/Windows/LiveWindowRightBottomBlock.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + 摄像头未开启 + + + + + + + + diff --git a/JianGongYun/TRTC/Windows/LiveWindowRightBottomBlock.xaml.cs b/JianGongYun/TRTC/Windows/LiveWindowRightBottomBlock.xaml.cs new file mode 100644 index 0000000..33a3b61 --- /dev/null +++ b/JianGongYun/TRTC/Windows/LiveWindowRightBottomBlock.xaml.cs @@ -0,0 +1,83 @@ +using JianGongYun.TRTC.Components; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace JianGongYun.TRTC.Windows +{ + /// + /// LiveWindowRightBottomBlock.xaml 的交互逻辑 + /// + public partial class LiveWindowRightBottomBlock : Window + { + LiveWindow LiveWindow { get; set; } + public LiveWindowRightBottomBlock(LiveWindow _liveWindow) + { + InitializeComponent(); + this.Left = SystemParameters.WorkArea.Size.Width - this.Width - 20; + this.Top = SystemParameters.WorkArea.Size.Height - this.Height - 20; + LiveWindow = _liveWindow; + DataContext = LiveWindow.LiveWindowViewModel; + if (!LiveWindow.LiveWindowViewModel.CameraRunning)//没有开启摄像头 + { + this.Height -= PreViewWrap.Height; + this.Top += PreViewWrap.Height; + PreViewWrap.Visibility = Visibility.Collapsed; + } + else + { + this.Height -= 100; + this.Top += 100; + Loaded += LiveWindowRightBottomBlock_Loaded; + } + } + + private void LiveWindowRightBottomBlock_Loaded(object sender, RoutedEventArgs e) + { + //把主窗口的摄像头预览移到悬浮窗 + if (LiveWindow.AfterLiveViewWrap.Children.Count == 1) + { + var view = LiveWindow.AfterLiveViewWrap.Children[0] as TXLiteAVVideoView; + BindingOperations.ClearBinding(view, TXLiteAVVideoView.WidthProperty); + BindingOperations.ClearBinding(view, TXLiteAVVideoView.HeightProperty); + view.Width = PreVideoWrap.Width; + view.Height = PreVideoWrap.Height; + LiveWindow.AfterLiveViewWrap.Children.Remove(view); + PreVideoWrap.Children.Add(view); + view.SetPause(false); + } + } + + protected override void OnClosing(CancelEventArgs e) + { + //关闭前还原预览 + if (PreVideoWrap.Children.Count == 1) + { + var view = PreVideoWrap.Children[0] as TXLiteAVVideoView; + view.SetPause(true); + view.Width = LiveWindow.AfterLiveViewWrap.ActualWidth; + view.Height = LiveWindow.AfterLiveViewWrap.ActualHeight; + view.SetBinding(TXLiteAVVideoView.WidthProperty, new Binding("ActualWidth") { Source = LiveWindow.AfterLiveViewWrap }); + view.SetBinding(TXLiteAVVideoView.HeightProperty, new Binding("ActualHeight") { Source = LiveWindow.AfterLiveViewWrap }); + PreVideoWrap.Children.Remove(view); + LiveWindow.AfterLiveViewWrap.Children.Add(view); + view.SetPause(false); + } + base.OnClosing(e); + } + + private void Window_MouseDown(object sender, MouseButtonEventArgs e) + { + this.DragMove(); + } + } +} diff --git a/JianGongYun/TRTC/Windows/LiveWindowTopBlock.xaml b/JianGongYun/TRTC/Windows/LiveWindowTopBlock.xaml new file mode 100644 index 0000000..dad1772 --- /dev/null +++ b/JianGongYun/TRTC/Windows/LiveWindowTopBlock.xaml @@ -0,0 +1,42 @@ + + + + + + + + + 直播中 + + + + 当前教室共有: + + + + + + diff --git a/JianGongYun/TRTC/Windows/LiveWindowTopBlock.xaml.cs b/JianGongYun/TRTC/Windows/LiveWindowTopBlock.xaml.cs new file mode 100644 index 0000000..35df42f --- /dev/null +++ b/JianGongYun/TRTC/Windows/LiveWindowTopBlock.xaml.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Forms; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using Application = System.Windows.Forms.Application; +using MouseEventArgs = System.Windows.Input.MouseEventArgs; + +namespace JianGongYun.TRTC.Windows +{ + /// + /// LiveWindowTopBlock.xaml 的交互逻辑 + /// + public partial class LiveWindowTopBlock : Window + { + LiveWindow LiveWindow { get; set; } + LiveWindowRightBottomBlock Child; + DpiScale dpi; + public LiveWindowTopBlock(LiveWindow _liveWindow) + { + InitializeComponent(); + this.Left = (SystemParameters.WorkArea.Size.Width - this.Width) / 2; + LiveWindow = _liveWindow; + DataContext = LiveWindow.LiveWindowViewModel; + dpi = VisualTreeHelper.GetDpi(this); + + Child = new LiveWindowRightBottomBlock(_liveWindow); + Child.Show(); + } + + protected override void OnClosing(CancelEventArgs e) + { + Child.Close(); + base.OnClosing(e); + } + + private void ShowLiveWin_Click(object sender, RoutedEventArgs e) + { + LiveWindow.Show(); + this.Close(); + } + + bool down = false; + double initX = 0; + + private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + down = false; + } + private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + //this.DragMove(); + initX = System.Windows.Forms.Control.MousePosition.X / dpi.DpiScaleX; + down = true; + } + //自定义拖动 + private void Window_MouseMove(object sender, MouseEventArgs e) + { + if (!down) + { + return; + } + var temp = System.Windows.Forms.Control.MousePosition.X / dpi.DpiScaleX; + var res = temp - initX; + if (this.Left + res < 0) + { + this.Dispatcher.Invoke(new Action(() => + { + this.Left = 0; + })); + } + else if (this.Left + res > SystemParameters.WorkArea.Size.Width - this.ActualWidth) + { + this.Dispatcher.Invoke(new Action(() => + { + this.Left = (int)SystemParameters.WorkArea.Size.Width - (int)this.ActualWidth; + })); + } + else + { + this.Dispatcher.Invoke(new Action(() => + { + this.Left += res; + })); + } + initX = temp; + } + + private void Window_MouseLeave(object sender, MouseEventArgs e) + { + down = false; + } + } +} diff --git a/JianGongYun/TRTC/Windows/SettingWindow.xaml.cs b/JianGongYun/TRTC/Windows/SettingWindow.xaml.cs index a9b1bc9..b0e2d4d 100644 --- a/JianGongYun/TRTC/Windows/SettingWindow.xaml.cs +++ b/JianGongYun/TRTC/Windows/SettingWindow.xaml.cs @@ -105,6 +105,7 @@ namespace JianGongYun.TRTC.Windows StartInfo = new ProcessStartInfo { FileName = "explorer.exe", Arguments = mode.ScreenRecordingDir } }; process.Start(); + process.WaitForExit(); } ///