コード例 #1
0
        private async void StopSpeak(SpeakModel obj)
        {
            ThrowIfPublishVerify();

            Participant.IsSpeaking = false;
            var resources = Participant.Resources.ToList();

            foreach (var streamResource in resources)
            {
                await Async.Create(() => Unpublish(streamResource.MediaType, streamResource.ResourceId))
                .TryRun("取消发布摄像头。");

                VideoBoxType videoBoxType;
                if (streamResource.MediaType.TryConvertVideoBoxType(out videoBoxType))
                {
                    VideoBoxManager.Release(Participant.Account.AccountId, videoBoxType);
                }
            }
            Participant.Resources.Clear();
            LayoutChanged(MediaType.Camera);
        }
コード例 #2
0
        private async void StartSpeak(SpeakModel obj)
        {
            if (_firstTimeToSpeak)
            {
                Monitor.Enter(_syncRoot);
                if (_firstTimeToSpeak)
                {
                    _firstTimeToSpeak = false;
                }
                Monitor.Exit(_syncRoot);
                return;
            }

            ThrowIfPublishVerify();

            Participant.IsSpeaking = true;

            Console.WriteLine($"_autoPublish:{_autoPublish}");

            if (_autoPublish)
            {
                IEnumerable <string> micDeviceName;
                if (!_deviceNameAccessor.TryGetName(DeviceName.Microphone, new Func <DeviceName, bool>(d => { return(d.Option == "first"); }), out micDeviceName))
                {
                    throw new Exception("麦克风未设置!");
                }
                await Async.Create(() => Publish(MediaType.Microphone, micDeviceName.FirstOrDefault())).TryRun("发布Microphone失败。");

                IEnumerable <string> cameraDeviceName;
                if (!_deviceNameAccessor.TryGetName(DeviceName.Camera, new Func <DeviceName, bool>(d => { return(d.Option == "first"); }), out cameraDeviceName))
                {
                    throw new Exception("人像摄像头未设置!");
                }
                await Async.Create(() => Publish(MediaType.Camera, cameraDeviceName.FirstOrDefault())).TryRun("发布Camera失败。");
            }
        }