public void Start(VideoChat videoChat, Action<string> callback)
        {
            // WebRTC audio and video streams require us to first get access to
            // the local media (microphone, camera, or both).
            UserMedia.GetMedia(new GetMediaArgs(Audio, Video)
            {
                // Specify an audio capture provider, a video
                // capture provider, an audio render provider,
                // and a video render provider. The IceLink
                // SDK comes bundled with video support for
                // WinForms and WPF, and uses NAudio for audio
                // support. For lower latency audio, use ASIO.
                AudioCaptureProvider = new NAudioCaptureProvider(),
                VideoCaptureProvider = new VideoCaptureProvider(),
                CreateAudioRenderProvider = (e) =>
                {
                    return new NAudioRenderProvider();
                },
                CreateVideoRenderProvider = (e) =>
                {
                    return new VideoRenderProvider(LayoutScale.Contain);
                },
                VideoWidth = VideoWidth,     // optional
                VideoHeight = VideoHeight,    // optional
                VideoFrameRate = VideoFrameRate, // optional
                OnFailure = (e) =>
                {
                    callback(string.Format("Could not get media. {0}", e.Exception.Message));
                },
                OnSuccess = (e) =>
                {
                    // We have successfully acquired access to the local
                    // audio/video device! Grab a reference to the media.
                    // Internally, it maintains access to the local audio
                    // and video feeds coming from the device hardware.
                    LocalMediaStream = e.LocalStream;

                    // Wire up the UI.
                    VideoChat = videoChat;
                    Win8LayoutManager.SafeInvoke(() =>
                    {
                        VideoChat.GetAudioDevices().ItemsSource = LocalMediaStream.GetAudioDeviceNames();
                        VideoChat.GetVideoDevices().ItemsSource = LocalMediaStream.GetVideoDeviceNames();
                        VideoChat.GetAudioDevices().SelectionChanged += SwitchAudioDevice;
                        VideoChat.GetVideoDevices().SelectionChanged += SwitchVideoDevice;
                        VideoChat.GetAudioDevices().SelectedIndex = LocalMediaStream.GetAudioDeviceNumber();
                        VideoChat.GetVideoDevices().SelectedIndex = LocalMediaStream.GetVideoDeviceNumber();
                    });

                    // Keep the UI updated if devices are switched.
                    LocalMediaStream.OnAudioDeviceNumberChanged += UpdateSelectedAudioDevice;
                    LocalMediaStream.OnVideoDeviceNumberChanged += UpdateSelectedVideoDevice;

                    // This is our local video control, a WinForms control
                    // that displays video coming from the capture source.
                    var localVideoControl = (FrameworkElement)e.LocalVideoControl;

                    // Create an IceLink layout manager, which makes the task
                    // of arranging video controls easy. Give it a reference
                    // to a WinForms control that can be filled with video feeds.
                    // Use WpfLayoutManager for WPF-based applications.
                    LayoutManager = new Win8LayoutManager(VideoChat.GetContainer());

                    // Display the local video control.
                    LayoutManager.SetLocalVideoControl(localVideoControl);

                    callback(null);
                }
            });
        }
Exemple #2
0
        public void Start(VideoChat videoChat, Action <string> callback)
        {
            // WebRTC audio and video streams require us to first get access to
            // the local media (microphone, camera, or both).
            UserMedia.GetMedia(new GetMediaArgs(Audio, Video)
            {
                // Specify an audio capture provider, a video
                // capture provider, an audio render provider,
                // and a video render provider. The IceLink
                // SDK comes bundled with video support for
                // WinForms and WPF, and uses NAudio for audio
                // support. For lower latency audio, use ASIO.
                AudioCaptureProvider      = new NAudioCaptureProvider(),
                VideoCaptureProvider      = new VideoCaptureProvider(),
                CreateAudioRenderProvider = (e) =>
                {
                    return(new NAudioRenderProvider());
                },
                CreateVideoRenderProvider = (e) =>
                {
                    return(new VideoRenderProvider(LayoutScale.Contain));
                },
                VideoWidth     = VideoWidth,     // optional
                VideoHeight    = VideoHeight,    // optional
                VideoFrameRate = VideoFrameRate, // optional
                OnFailure      = (e) =>
                {
                    callback(string.Format("Could not get media. {0}", e.Exception.Message));
                },
                OnSuccess = (e) =>
                {
                    // We have successfully acquired access to the local
                    // audio/video device! Grab a reference to the media.
                    // Internally, it maintains access to the local audio
                    // and video feeds coming from the device hardware.
                    LocalMediaStream = e.LocalStream;

                    // Wire up the UI.
                    VideoChat = videoChat;
                    Win8LayoutManager.SafeInvoke(() =>
                    {
                        VideoChat.GetAudioDevices().ItemsSource       = LocalMediaStream.GetAudioDeviceNames();
                        VideoChat.GetVideoDevices().ItemsSource       = LocalMediaStream.GetVideoDeviceNames();
                        VideoChat.GetAudioDevices().SelectionChanged += SwitchAudioDevice;
                        VideoChat.GetVideoDevices().SelectionChanged += SwitchVideoDevice;
                        VideoChat.GetAudioDevices().SelectedIndex     = LocalMediaStream.GetAudioDeviceNumber();
                        VideoChat.GetVideoDevices().SelectedIndex     = LocalMediaStream.GetVideoDeviceNumber();
                    });

                    // Keep the UI updated if devices are switched.
                    LocalMediaStream.OnAudioDeviceNumberChanged += UpdateSelectedAudioDevice;
                    LocalMediaStream.OnVideoDeviceNumberChanged += UpdateSelectedVideoDevice;

                    // This is our local video control, a WinForms control
                    // that displays video coming from the capture source.
                    var localVideoControl = (FrameworkElement)e.LocalVideoControl;

                    // Create an IceLink layout manager, which makes the task
                    // of arranging video controls easy. Give it a reference
                    // to a WinForms control that can be filled with video feeds.
                    // Use WpfLayoutManager for WPF-based applications.
                    LayoutManager = new Win8LayoutManager(VideoChat.GetContainer());

                    // Display the local video control.
                    LayoutManager.SetLocalVideoControl(localVideoControl);

                    callback(null);
                }
            });
        }
Exemple #3
0
        public void Start(object videoContainer, Action <string> callback)
        {
#if __IOS__
            AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.PlayAndRecord,
                                                        AVAudioSessionCategoryOptions.AllowBluetooth |
                                                        AVAudioSessionCategoryOptions.DefaultToSpeaker);
#endif

            UserMedia.GetMedia(new GetMediaArgs(Audio, Video)
            {
#if __IOS__ || __ANDROID__
#elif WINDOWS_APP
                AudioCaptureProvider      = new NAudioCaptureProvider(),
                VideoCaptureProvider      = new VideoCaptureProvider(),
                CreateAudioRenderProvider = (e) =>
                {
                    return(new NAudioRenderProvider());
                },
                CreateVideoRenderProvider = (e) =>
                {
                    return(new VideoRenderProvider(LayoutScale.Contain));
                },
#endif

                VideoWidth               = VideoWidth,          // optional
                VideoHeight              = VideoHeight,         // optional
                VideoFrameRate           = VideoFrameRate,      // optional
                DefaultVideoPreviewScale = LayoutScale.Contain, // optional
                DefaultVideoScale        = LayoutScale.Contain, // optional
                OnFailure = (e) =>
                {
                    callback(string.Format("Could not get media. {0}", e.Exception.Message));
                },
                OnSuccess = (e) =>
                {
                    // We have successfully acquired access to the local
                    // audio/video device! Grab a reference to the media.
                    // Internally, it maintains access to the local audio
                    // and video feeds coming from the device hardware.
                    LocalMediaStream = e.LocalStream;

                    // This is our local video control, a UIView (iOS) or
                    // and NSView (Mac). It is constantly updated with our
                    // live video feed since we requested video above. Add
                    // it directly to the UI or use the IceLink layout manager,
                    // which we do below.
                    var localVideoControl = e.LocalVideoControl;

#if __IOS__ || __ANDROID__
                    // Create an IceLink layout manager, which makes the task
                    // of arranging video controls easy. Give it a reference
                    // to a UIView that can be filled with video feeds.
                    LayoutManager = new FormsLayoutManager((AbsoluteLayout)videoContainer);

                    // Position and display the local video control on-screen
                    // by passing it to the layout manager created above.
                    LayoutManager.SetLocalVideoControl(new FormsVideoControl(localVideoControl));
#elif WINDOWS_APP
                    var content = Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.Frame;
                    var list    = new List <Windows.UI.Xaml.Controls.Canvas>();
                    FindChildren <Windows.UI.Xaml.Controls.Canvas>(list, content.Content as Windows.UI.Xaml.DependencyObject);

                    // Create an IceLink layout manager, which makes the task
                    // of arranging video controls easy. Give it a reference
                    // to a WinForms control that can be filled with video feeds.
                    // Use WpfLayoutManager for WPF-based applications.
                    LayoutManager = new Win8LayoutManager(list.Last());

                    // Position and display the local video control on-screen
                    // by passing it to the layout manager created above.
                    LayoutManager.SetLocalVideoControl(localVideoControl);
#endif



                    callback(null);
                }
            });
        }