This commit is contained in:
lxmou666 2020-12-29 23:46:15 +08:00
parent 7c47e0ea0f
commit 8d8cb28d66
5 changed files with 70 additions and 22 deletions

View File

@ -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
/// </summary>
public event Action<WriteableBitmap> OnRenderVideoFrameHandler;
public event Action OnViewRemove;
private void RenderFillMode(DrawingContext dc, byte[] data, int width, int height, int rotation)
{

View File

@ -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);

View File

@ -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
}
}
}
/// <summary>
/// WriteableBitmap转Bitmap
/// </summary>
/// <param name="writeableBitmap"></param>
/// <returns></returns>
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);
}
}
}
}

View File

@ -178,6 +178,25 @@ namespace JianGongYun.TRTC.ViewModels
}
}
/// <summary>
/// 麦克风录音中
/// </summary>
private bool _AudioRecordRunning = false;
public bool AudioRecordRunning
{
set
{
_AudioRecordRunning = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("AudioRecordRunning"));
}
}
get
{
return _AudioRecordRunning;
}
}
/// <summary>
/// 麦克风静音
/// </summary>
private bool _MicMute = false;

View File

@ -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)));
// }
//}