JianGongYun/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs

214 lines
5.9 KiB
C#

using JianGongYun.TRTC.Models;
using ManageLiteAV;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using System.Windows.Threading;
namespace JianGongYun.TRTC.ViewModels
{
public class LiveWindowViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// 教室信息
/// </summary>
public Models.ClassroomEntity ClassroomEntity { get { return LiveClassroom.CurrentClassroomEntity; } }
/// <summary>
/// 学生总数
/// </summary>
private int _StudentCount = 0;
public int StudentCount
{
set
{
_StudentCount = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("StudentCount"));//对StudentCount进行监听
}
}
get
{
return _StudentCount;
}
}
/// <summary>
/// 是否在直播中
/// </summary>
private bool _IsLive = false;
public bool IsLive
{
set
{
_IsLive = value;
if (value)//开始直播,清空时间并开始计时
{
_LiveTimeCount = new DateTime(1970, 1, 1, 0, 0, 0);
timer.Start();
}
else
{
timer.Stop();
}
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("IsLive"));
}
}
get
{
return _IsLive;
}
}
public LiveWindowViewModel()
{
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += new EventHandler((a, b) => LiveTimeCount = "");
}
/// <summary>
/// 直播计时器
/// </summary>
private DispatcherTimer timer = null;
private DateTime _LiveTimeCount;
public string LiveTimeCount
{
get
{
return _LiveTimeCount.ToString("HH:mm:ss");
}
set
{
_LiveTimeCount = _LiveTimeCount.AddSeconds(1);
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("LiveTimeCount"));
}
}
}
/// <summary>
/// 直播类型
/// </summary>
private LiveTypeEnum _LiveType = LiveTypeEnum.OnlyAudio;
public LiveTypeEnum LiveType
{
set
{
_LiveType = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("LiveType"));
}
}
get
{
return _LiveType;
}
}
/// <summary>
/// 摄像头采集中
/// </summary>
private bool _CameraRunning = false;
public bool CameraRunning
{
set
{
_CameraRunning = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("CameraRunning"));
}
}
get
{
return _CameraRunning;
}
}
/// <summary>
/// 屏幕分享中
/// </summary>
private bool _ScreenRunning = false;
public bool ScreenRunning
{
set
{
_ScreenRunning = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("ScreenRunning"));
}
}
get
{
return _ScreenRunning;
}
}
/// <summary>
/// 麦克风使用中
/// </summary>
private bool _MicRunning = false;
public bool MicRunning
{
set
{
_MicRunning = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("MicRunning"));
}
}
get
{
return _MicRunning;
}
}
private SIZE thumbSize = new SIZE { cx = 300, cy = 200 };
private SIZE iconSize = new SIZE { cx = 50, cy = 50 };
private ObservableCollection<TRTCScreenCaptureSourceInfo> _LiveScreens = new ObservableCollection<TRTCScreenCaptureSourceInfo>();
/// <summary>
/// 可分享桌面
/// </summary>
public ObservableCollection<TRTCScreenCaptureSourceInfo> LiveScreens
{
get
{
_LiveScreens.Clear();
var temp = LiveClassroom.lTRTCCloud.getScreenCaptureSources(ref thumbSize, ref iconSize);
var count = temp.getCount();
for (uint i = 0; i < count; i++)
{
_LiveScreens.Add(temp.getSourceInfo(i));
}
temp.release();
return _LiveScreens;
}
}
private IntPtr _CurrentShareScreen;
public IntPtr CurrentShareScreen
{
get { return _CurrentShareScreen; }
set
{
_CurrentShareScreen = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("CurrentShareScreen"));
}
}
}
}
}