diff --git a/JianGongYun/TRTC/Components/TXLiteAVVideoView.cs b/JianGongYun/TRTC/Components/TXLiteAVVideoView.cs index 2166104..3e67cee 100644 --- a/JianGongYun/TRTC/Components/TXLiteAVVideoView.cs +++ b/JianGongYun/TRTC/Components/TXLiteAVVideoView.cs @@ -105,6 +105,7 @@ namespace JianGongYun.TRTC.Components mLocalView = false; mFirstFrame = false; mRenderMode = TRTCVideoFillMode.TRTCVideoFillMode_Fit; + this.OnViewRemove?.Invoke(); this.InvalidateVisual(); } @@ -231,6 +232,7 @@ namespace JianGongYun.TRTC.Components /// 渲染回调int width, int height, int rotation,WriteableBitmap image /// public event Action OnRenderVideoFrameHandler; + public event Action OnViewRemove; private void RenderFillMode(DrawingContext dc, byte[] data, int width, int height, int rotation) { diff --git a/JianGongYun/TRTC/LiveClassroom.cs b/JianGongYun/TRTC/LiveClassroom.cs index 1151568..2d6aa0e 100644 --- a/JianGongYun/TRTC/LiveClassroom.cs +++ b/JianGongYun/TRTC/LiveClassroom.cs @@ -15,6 +15,7 @@ using System.Windows; using System.Windows.Controls; using Window = System.Windows.Window; using System.Collections.Concurrent; +using System.Windows.Data; namespace JianGongYun.TRTC { @@ -234,10 +235,13 @@ namespace JianGongYun.TRTC { liveWinMode.MicRunning = true; lTRTCCloud.startLocalAudio(settingWindowViewModel.LiveAudioLevel); - if (liveWinMode.IsLive) + if (liveWinMode.IsLive && !liveWinMode.AudioRecordRunning) { - var pars = new TRTCAudioRecordingParams { filePath = "" }; - lTRTCCloud.startAudioRecording(ref pars); + liveWinMode.AudioRecordRunning = true; + var time = DateTime.Now.ToString("yyyyMMddHHmmssfff"); + var pars = new TRTCAudioRecordingParams { filePath = Path.Combine(RecoderDir, $"{time}audio.pcm") }; + var res = lTRTCCloud.startAudioRecording(ref pars); + Console.WriteLine(res); } } } @@ -249,6 +253,11 @@ namespace JianGongYun.TRTC if (liveWinMode.MicRunning) { liveWinMode.MicRunning = false; + if (liveWinMode.AudioRecordRunning) + { + liveWinMode.AudioRecordRunning = false; + lTRTCCloud.stopAudioRecording(); + } lTRTCCloud.stopLocalAudio(); } } @@ -272,8 +281,10 @@ namespace JianGongYun.TRTC TXLiteAVVideoView videoView = new TXLiteAVVideoView(); videoView.RegEngine(userId, streamType, lTRTCCloud, local); videoView.SetRenderMode(streamType == TRTCVideoStreamType.TRTCVideoStreamTypeBig ? settingWindowViewModel.RenderParams.fillMode : TRTCVideoFillMode.TRTCVideoFillMode_Fit); - videoView.Width = parent.ActualWidth; - videoView.Height = parent.ActualHeight; + //videoView.Width = parent.ActualWidth; + videoView.SetBinding(TXLiteAVVideoView.WidthProperty, new Binding("ActualWidth") { Source = parent }); + //videoView.Height = parent.ActualHeight; + videoView.SetBinding(TXLiteAVVideoView.HeightProperty, new Binding("ActualHeight") { Source = parent }); parent.Dispatcher.Invoke(new Action(() => { parent.Children.Add(videoView); diff --git a/JianGongYun/TRTC/Utils/WriteableBitmapToMat.cs b/JianGongYun/TRTC/Utils/WriteableBitmapToMat.cs index 6e8e8a4..579e8ce 100644 --- a/JianGongYun/TRTC/Utils/WriteableBitmapToMat.cs +++ b/JianGongYun/TRTC/Utils/WriteableBitmapToMat.cs @@ -1,6 +1,7 @@ using OpenCvSharp; using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Text; using System.Windows.Media.Imaging; @@ -18,7 +19,7 @@ namespace JianGongYun.TRTC.Utils { using (MemoryStream outStream = new MemoryStream()) { - BitmapEncoder enc = new JpegBitmapEncoder(); + BitmapEncoder enc = new PngBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(writeableBitmap)); enc.Save(outStream); using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(outStream)) @@ -28,5 +29,20 @@ namespace JianGongYun.TRTC.Utils } } } + /// + /// WriteableBitmap转Bitmap + /// + /// + /// + public static Bitmap ToBitmap(this WriteableBitmap writeableBitmap) + { + using (MemoryStream outStream = new MemoryStream()) + { + BitmapEncoder enc = new PngBitmapEncoder(); + enc.Frames.Add(BitmapFrame.Create(writeableBitmap)); + enc.Save(outStream); + return new System.Drawing.Bitmap(outStream); + } + } } } diff --git a/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs b/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs index 0a7d551..d4b2c4d 100644 --- a/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs +++ b/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs @@ -178,6 +178,25 @@ namespace JianGongYun.TRTC.ViewModels } } /// + /// 麦克风录音中 + /// + private bool _AudioRecordRunning = false; + public bool AudioRecordRunning + { + set + { + _AudioRecordRunning = value; + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs("AudioRecordRunning")); + } + } + get + { + return _AudioRecordRunning; + } + } + /// /// 麦克风静音 /// private bool _MicMute = false; diff --git a/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs b/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs index ae11ace..cf119c4 100644 --- a/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs +++ b/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs @@ -32,8 +32,8 @@ namespace JianGongYun.TRTC.Windows public LiveWindow() { InitializeComponent(); - BeforeLiveSubViewWrap.SizeChanged += BeforeLiveSubViewWrap_SizeChanged; - AfterLiveSubViewWrap.SizeChanged += AfterLiveSubViewWrap_SizeChanged; + //BeforeLiveSubViewWrap.SizeChanged += BeforeLiveSubViewWrap_SizeChanged; + //AfterLiveSubViewWrap.SizeChanged += AfterLiveSubViewWrap_SizeChanged; AttachConsole(-1);//把进程挂在控制台,通过命令行启动程序可以看到控制台输出 LiveWindowViewModel = new ViewModels.LiveWindowViewModel(); SettingWindowViewModel = ViewModels.SettingWindowViewModel.GetInstance(); @@ -41,21 +41,21 @@ namespace JianGongYun.TRTC.Windows 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 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))); - } - } + //private void BeforeLiveSubViewWrap_SizeChanged(object sender, SizeChangedEventArgs e) + //{ + // if (!LiveWindowViewModel.IsLive) + // { + // this.Dispatcher.Invoke(new Action(() => LiveClassroom.ResizeVideoSub(BeforeLiveSubViewWrap))); + // } + //}