private void btn_ls_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(rt_push_url.Text)) { MessageBox.Show("推流地址不能为空!"); return; } NIMDeviceInfoList cameraDeviceinfolist = NIM.DeviceAPI.GetDeviceList(NIM.NIMDeviceType.kNIMDeviceTypeVideo); if (cameraDeviceinfolist == null) { MessageBox.Show("没有摄像头,无法直播!!!"); return; } pullurl_ = rt_push_url.Text; if (nimSDKHelper.session == null) { nimSDKHelper.form = this; nimSDKHelper.session = new LsSession(); nimSDKHelper.session.InitSession(false, pullurl_); nimSDKHelper.session.DoStartLiveStream(); btn_ls.Text = "结束直播"; } else { nimSDKHelper.session.DoStopLiveStream(); nimSDKHelper.session.ClearSession(); nimSDKHelper.session = null; btn_ls.Text = "开始直播"; } }
public static void StartDevices() { NIM.StartDeviceResultHandler handle = (type, ret) => { System.Diagnostics.Debug.WriteLine(type.ToString() + ":" + ret.ToString()); }; NIM.DeviceAPI.StartDevice(NIM.NIMDeviceType.kNIMDeviceTypeAudioIn, "", 0, null, handle); //开启麦克风 NIM.DeviceAPI.StartDevice(NIM.NIMDeviceType.kNIMDeviceTypeAudioOutChat, "", 0, null, handle); //开启扬声器播放对方语音 NIMDeviceInfoList device_list = NIM.DeviceAPI.GetDeviceList(NIM.NIMDeviceType.kNIMDeviceTypeVideo); if (device_list.DeviceList.Count > 0) { NIM.DeviceAPI.StartDevice(NIM.NIMDeviceType.kNIMDeviceTypeVideo, device_list.DeviceList[0].Path, 0, null, handle);//开启摄像头 } }
//public void RequestEnter(string roomid) //{ // NIMChatRoom.ChatRoomApi.LoginHandler += ChatRoomApi_LoginHandler; // room_id_ = roomid; // string json_info = ""; // StringWriter sw = new StringWriter(); // JsonWriter writer = new JsonTextWriter(sw); // writer.WriteStartObject(); // writer.WritePropertyName("type"); // writer.WriteValue(Convert.ToInt16(living_model_)); // writer.WritePropertyName("meetingName"); // writer.WriteValue(room_name_); // writer.WriteEndObject(); // writer.Flush(); // json_info = sw.GetStringBuilder().ToString(); // NIM.Plugin.RequestChatRoomLoginInfoDelegate cb = (code, result) => // { // if(code!= ResponseCode.kNIMResSuccess) // { // Action action = ()=>{ // MessageBox.Show("进入房间失败"); // }; // this.BeginInvoke(action); // } // else // { // Action action = () => // { // rt_prompt_info.Text += "进入房间成功\n"; // }; // this.BeginInvoke(action); // if (!String.IsNullOrEmpty(result)) // { // room_enter_token_ = result; // NIMChatRoom.ChatRoomApi.Login(Convert.ToInt64(room_id_), room_enter_token_); // } // } // }; // NIM.Plugin.ChatRoom.RequestLoginInfo(Convert.ToInt64(roomid), cb, json_info); //} //private void ChatRoomApi_LoginHandler(NIMChatRoom.NIMChatRoomLoginStep loginStep, ResponseCode errorCode, NIMChatRoom.ChatRoomInfo roomInfo, NIMChatRoom.MemberInfo memberInfo) //{ // if (loginStep != NIMChatRoom.NIMChatRoomLoginStep.kNIMChatRoomLoginStepRoomAuthOver) // return; // if (errorCode != ResponseCode.kNIMResSuccess && errorCode != ResponseCode.kNIMResTimeoutError) // { // this.RequestEnter(room_id_); // return; // } // else // { // EnteredOperate(errorCode, roomInfo, memberInfo); // } //} //进入房间之后的处理 //private void EnteredOperate(ResponseCode error_code,NIMChatRoom.ChatRoomInfo roomInfo,NIMChatRoom.MemberInfo memberInfo) //{ // if(error_code!=ResponseCode.kNIMResSuccess) // { // Close(); // return; // } // if(0==roomInfo.RoomId) // { // return; // } // room_id_ = roomInfo.RoomId.ToString(); // room_name_ = roomInfo.RoomName; // if (!IsDisposed &&this.IsHandleCreated) // { // this.Invoke(new Action(() => { this.Text = room_name_; })); // } // RequestAddress(room_id_,Helper.UserHelper.SelfId); // InitChatRoomQueueInfo(); //} private void btn_start_ls_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(rt_push_url_)) { MessageBox.Show("推流地址不能为空!"); return; } NIMDeviceInfoList cameraDeviceinfolist = NIM.DeviceAPI.GetDeviceList(NIM.NIMDeviceType.kNIMDeviceTypeVideo); if (cameraDeviceinfolist == null) { MessageBox.Show("没有摄像头,无法直播!!!"); return; } }
//初始化设备列表 private void InitDevicesCombolist() { NIMDeviceInfoList cameraDeviceinfolist = NIM.DeviceAPI.GetDeviceList(NIM.NIMDeviceType.kNIMDeviceTypeVideo); NIMDeviceInfoList micphoneDeviceinfolist = NIM.DeviceAPI.GetDeviceList(NIM.NIMDeviceType.kNIMDeviceTypeAudioIn); NIMDeviceInfoList audioOutDeviceinfolist = NIM.DeviceAPI.GetDeviceList(NIM.NIMDeviceType.kNIMDeviceTypeAudioOut); if (cameraDeviceinfolist != null) { _cameraDeviceList = cameraDeviceinfolist.DeviceList; } if (micphoneDeviceinfolist != null) { _micphoneDeviceList = micphoneDeviceinfolist.DeviceList; } if (audioOutDeviceinfolist != null) { _audioOutDeviceList = audioOutDeviceinfolist.DeviceList; } if (_cameraDeviceList != null) { foreach (var device in _cameraDeviceList) { cb_camera.Items.Add(device.Name); } cb_camera.SelectedIndex = 0; } if (_micphoneDeviceList != null) { foreach (var device in _micphoneDeviceList) { cb_microphone.Items.Add(device.Name); } cb_microphone.SelectedIndex = 0; } if (_audioOutDeviceList != null) { foreach (var device in _audioOutDeviceList) { cb_audiooutdevice.Items.Add(device.Name); } cb_audiooutdevice.SelectedIndex = 0; } }