Example #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            /* LocalMedia represents our local camera and microphone (media) configuration */
            localMedia = new LocalMedia(this);

            if (ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.DEVICE)
            {
                /* Microphone is enabled by default, to enable Camera, we first create a Camera capturer */
                camera = localMedia.AddCameraTrack();
            }
            else
            {
                localVideoContainer.Hidden = true;
                pauseButton.Enabled        = false;
                flipCameraButton.Enabled   = false;
            }

            /*
             * We attach a view to display our local camera track immediately.
             * You could also wait for localMedia:addedVideoTrack to attach a view or add a renderer.
             */
            if (camera != null)
            {
                camera.VideoTrack.Attach(localVideoContainer);
                camera.VideoTrack.Delegate = this;
            }

            /* For this demonstration, we always use Speaker audio output (vs. TWCAudioOutputReceiver) */
            TwilioConversationsClient.SetAudioOutput(AudioOutput.Speaker);
        }
Example #2
0
        public void DidRemoveVideoTrack(LocalMedia media, VideoTrack videoTrack)
        {
            Console.WriteLine("Local video track removed: {0}", videoTrack);

            /* You do not need to call [videoTrack detach:] here, your view will be detached once this call returns. */
            camera = null;
        }
Example #3
0
        public async Task CaptureMedia(long fromUid, bool r = false)
        {
            LocalMedia = Media.CreateMedia();                                                  //创建一个Media对象

            RTCMediaStreamConstraints mediaStreamConstraints = new RTCMediaStreamConstraints() //设置要获取的流
            {
                audioEnabled = true,
                videoEnabled = true
            };

            //音频播放
            var apd = LocalMedia.GetAudioPlayoutDevices();

            if (apd.Count > 0)
            {
                LocalMedia.SelectAudioPlayoutDevice(apd[0]);
            }



            if (fromUid == 0)
            {
                //音频捕获
                var acd = LocalMedia.GetAudioCaptureDevices();
                if (acd.Count > 0)
                {
                    mediaStreamConstraints.audioEnabled = true;
                    LocalMedia.SelectAudioCaptureDevice(acd[0]);
                }
                //视频捕获
                var vcd = LocalMedia.GetVideoCaptureDevices();
                if (vcd.Count > 0)
                {
                    mediaStreamConstraints.videoEnabled = true;
                    LocalMedia.SelectVideoDevice(vcd.First(p => p.Location.Panel == Windows.Devices.Enumeration.Panel.Front));//设置视频捕获设备
                }
            }



            var mediaStream = await LocalMedia.GetUserMedia(mediaStreamConstraints);//获取视频流 这里视频和音频是一起传输的

            if (fromUid == 0)
            {
                var videotracs = mediaStream.GetVideoTracks();
                if (videotracs.Count > 0)
                {
                    var source = LocalMedia.CreateMediaSource(videotracs.FirstOrDefault(), mediaStream.Id); //创建播放源
                    LocalMediaPlayer.SetMediaStreamSource(source);                                          //设置MediaElement的播放源
                    LocalMediaPlayer.Play();
                }
                await CreatePublisher(mediaStream);

                //await CreateServer(mediaStream);
            }
            else
            {
                await CreateReceiver(mediaStream, fromUid);
            }
        }
		public override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);
			ContentView = R.layout.activity_screen_capturer;
			localVideoView = (VideoView) findViewById(R.id.local_video);

			localMedia = LocalMedia.create(this);
		}
Example #5
0
        public override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView    = R.layout.activity_screen_capturer;
            localVideoView = (VideoView)findViewById(R.id.local_video);

            localMedia = LocalMedia.create(this);
        }
Example #6
0
        private static void Start()
        {
            var socket = new RtcSocket(
                "ws://localhost:8124/",
                Guid.NewGuid().ToString(),
                null,
                new Dictionary <string, object> {
                { "name", "Hello" },
                { "type", "device" }
            });

            //*
            var videoSource = new LocalMediaSource("video");
            //videoSource.source = "WN_L7501_V1";
            //screen-capture-recorder无法正常工作
            //videoSource.source = "screen-capture-recorder";

            /*/
             * var videoSource = new ScreenSource();
             * //*/
            var media = new LocalMedia(videoSource, new LocalMediaSource("audio"));
            var call  = new RtcCall(new[] {
                new RtcIceServer {
                    urls = new [] { "stun:stun.l.google.com:19302" }
                }
            }, socket, media);

            call.Query += (query, info) =>
            {
                query.Video = false;
                query.Audio = false;
            };

            call.Call += link =>
            {
                link.registerDataChannel("data");
                link.DataChannel += channel =>
                {
                    channel.Message += msg => Console.WriteLine("datachannel: " + msg);
                    var timer = Timeout.setInterval(() => channel.Send(DateTime.Now.ToString()), 1000);
                    channel.Closed += () =>
                    {
                        timer.clearInterval();
                        Console.WriteLine("data channel closed.");
                    };
                };
                link.Closed += () => { };
            };

            call.join("test-room");
            Task.Factory.StartNew(async() =>
            {
                await call.local.open();
                await socket.connect();
            });
        }
Example #7
0
 protected internal override void onDestroy()
 {
     if (localMedia != null)
     {
         if (screenVideoTrack != null)
         {
             localMedia.removeVideoTrack(screenVideoTrack);
         }
         localMedia.release();
         localMedia = null;
     }
     base.onDestroy();
 }
Example #8
0
        protected internal override void onDestroy()
        {
            /*
             * Release local media when no longer needed
             */
            if (localMedia != null)
            {
                localMedia.release();
                localMedia = null;
            }

            base.onDestroy();
        }
Example #9
0
        private void createLocalMedia()
        {
            localMedia = LocalMedia.create(this);

            // Share your microphone
            localAudioTrack = localMedia.addAudioTrack(true);

            // Share your camera
            cameraCapturer          = new CameraCapturer(this, CameraCapturer.CameraSource.FRONT_CAMERA);
            localVideoTrack         = localMedia.addVideoTrack(true, cameraCapturer);
            primaryVideoView.Mirror = true;
            localVideoTrack.addRenderer(primaryVideoView);
            localVideoView = primaryVideoView;
        }
Example #10
0
        public override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_custom_capturer;

            localMedia   = LocalMedia.create(this);
            capturedView = (LinearLayout)findViewById(R.id.captured_view);
            videoView    = (VideoView)findViewById(R.id.video_view);
            timerView    = (Chronometer)findViewById(R.id.timer_view);
            timerView.start();

            // Once added we should see our linear layout rendered live below
            localVideoTrack = localMedia.addVideoTrack(true, new ViewCapturer(capturedView));
            localVideoTrack.addRenderer(videoView);
        }
		public override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);
			ContentView = R.layout.activity_custom_capturer;

			localMedia = LocalMedia.create(this);
			capturedView = (LinearLayout) findViewById(R.id.captured_view);
			videoView = (VideoView) findViewById(R.id.video_view);
			timerView = (Chronometer) findViewById(R.id.timer_view);
			timerView.start();

			// Once added we should see our linear layout rendered live below
			localVideoTrack = localMedia.addVideoTrack(true, new ViewCapturer(capturedView));
			localVideoTrack.addRenderer(videoView);
		}
Example #12
0
        private void Conn_OnAddStream(MediaStreamEvent __param0)
        {
            var stream = __param0.Stream;

            var videotracks = stream.GetVideoTracks();
            //var media = Media.CreateMedia();

            //var apd = media.GetAudioPlayoutDevices();
            //if (apd.Count > 0)
            //{
            //    media.SelectAudioPlayoutDevice(apd[0]);
            //}

            var source = LocalMedia.CreateMediaSource(videotracks.FirstOrDefault(), stream.Id);

            RemoteMediaPlayer.SetMediaStreamSource(source);

            RemoteMediaPlayer.Play();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // LocalMedia represents the collection of tracks that we are sending to other Participants from our VideoClient.
            localMedia = new LocalMedia();

            // Wire up event handlers for VideoRoomDelegate
            // Purposefully wiring up every event.
            // Should Dispose of these.
            roomDelegate = new VideoRoomDelegate();
            roomDelegate.OnDidConnectToRoom        += HandleOnDidConnectToRoom;
            roomDelegate.OnDisconnectedWithError   += HandleOnDisconnectedWithError;
            roomDelegate.OnRoomFailedToConnect     += HandleOnRoomFailedToConnect;
            roomDelegate.OnParticipantDidConnect   += HandleOnParticipantDidConnect;
            roomDelegate.OnParticipantDisconnected += HandleOnParticipantDidConnect;

            // Wire up event handlers for VideoParticipantDelegate
            // Purposefully wiring up every event.
            // Should Dispose of these.
            participantDelegate = new VideoParticipantDelegate();
            participantDelegate.OnAddedVideoTrack   += HandleOnAddedVideoTrack;
            participantDelegate.OnRemovedVideoTrack += HandleOnRemovedVideoTrack;
            participantDelegate.OnAddedAudioTrack   += HandleOnAddedAudioTrack;
            participantDelegate.OnRemovedAudioTrack += HandleOnRemovedAudioTrack;
            participantDelegate.OnEnabledTrack      += HandleOnEnabledTrack;
            participantDelegate.OnDisabledTrack     += HandleOnDisabledTrack;

            if (IsSimulator)
            {
                previewView.RemoveFromSuperview();
            }
            else
            {
                // Preview our local camera track in the local video preview view.
                StartPreview();
            }

            // Disconnect and mic button will be displayed when client is connected to a room.
            disconnectButton.Hidden = true;
            micButton.Hidden        = true;
            // Should dispose of this.
            roomTextField.ShouldReturn += (textField) => { ConnectButtonPressed(textField); return(true); };
        }
Example #14
0
        private void SetupCall()
        {
            Signalling Signalling = new Signalling(Constants.WEB_SYNC_SERVER);

            Signalling.Start((error) =>
            {
                if (error != null)
                {
                    // TODO: Handle Errors
                }
            });

            LocalMedia = new LocalMedia();
            LocalMedia.Start(Container, (error) =>
            {
                if (error != null)
                {
                    //TODO: Handle Errors
                }
            });

            var audioStream = new AudioStream(LocalMedia.LocalMediaStream);
            var videoStream = new VideoStream(LocalMedia.LocalMediaStream);
            var conference  = new Conference(Constants.ICE_LINK_ADDRESS, new Stream[]
            {
                audioStream,
                videoStream
            });

            conference.RelayUsername = "******";
            conference.RelayPassword = "******";

            Signalling.Attach(conference, Constants.SESSION_ID, (error) =>
            {
                if (error != null)
                {
                    // TODO: Handle Errors
                }
            });
        }
		public override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);
			ContentView = R.layout.activity_custom_renderer;

			localMedia = LocalMedia.create(this);
			localVideoView = (VideoView) findViewById(R.id.local_video);
			snapshotImageView = (ImageView) findViewById(R.id.image_view);
			tapForSnapshotTextView = (TextView) findViewById(R.id.tap_video_snapshot);

			/*
			 * Check camera permissions. Needed in Android M.
			 */
			if (!checkPermissionForCamera())
			{
				requestPermissionForCamera();
			}
			else
			{
				addVideo();
			}
		}
        public override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_custom_renderer;

            localMedia             = LocalMedia.create(this);
            localVideoView         = (VideoView)findViewById(R.id.local_video);
            snapshotImageView      = (ImageView)findViewById(R.id.image_view);
            tapForSnapshotTextView = (TextView)findViewById(R.id.tap_video_snapshot);

            /*
             * Check camera permissions. Needed in Android M.
             */
            if (!checkPermissionForCamera())
            {
                requestPermissionForCamera();
            }
            else
            {
                addVideo();
            }
        }
Example #17
0
        public override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_advanced_camera_capturer;

            localMedia        = LocalMedia.create(this);
            videoView         = (VideoView)findViewById(R.id.video_view);
            toggleFlashButton = (Button)findViewById(R.id.toggle_flash_button);
            takePictureButton = (Button)findViewById(R.id.take_picture_button);
            pictureImageView  = (ImageView)LayoutInflater.inflate(R.layout.picture_image_view, null);
            pictureDialog     = (new AlertDialog.Builder(this)).setView(pictureImageView).setTitle(null).setPositiveButton([email protected], new OnClickListenerAnonymousInnerClassHelper(this))
                                .create();

            if (!checkPermissionForCamera())
            {
                requestPermissionForCamera();
            }
            else
            {
                addCameraVideo();
            }
        }
Example #18
0
        public async Task CreateReceiver(MediaStream mediaStream, long fromUid)
        {
            var conn = new RTCPeerConnection(RtcConfig);

            CurrentRoom.Recvs.Add(fromUid, conn);
            CurrentRoom.Recvs[fromUid].AddStream(mediaStream);
            CurrentRoom.Recvs[fromUid].OnIceCandidate += async(p) =>
            {
                var Candidate = p.Candidate;
                var m         = new SendCadidatModel();
                m.candidate = new CandidateModel
                {
                    candidate     = Candidate.Candidate,
                    sdpMlineindex = Candidate.SdpMLineIndex,
                    sdpMid        = Candidate.SdpMid,
                };
                m.uid     = Uid;
                m.fromUid = fromUid;
                Candidates.Add(m);
                await SendCandidate(m);
            };
            CurrentRoom.Recvs[fromUid].OnAddStream += (p) =>
            {
                var stream = p.Stream;

                var videotracks = stream.GetVideoTracks();


                var source = LocalMedia.CreateMediaSource(videotracks.FirstOrDefault(), stream.Id);

                RemoteMediaPlayer.SetMediaStreamSource(source);

                RemoteMediaPlayer.Play();
            };

            await CreatOffer(Uid, fromUid);
        }
Example #19
0
 void DismissConversation()
 {
     localMedia   = null;
     conversation = null;
     DismissViewControllerAsync(true);
 }
 private void PrepareLocalMedia()
 {
     localMedia      = new LocalMedia();
     localAudioTrack = localMedia.AddAudioTrack(true);
 }
Example #21
0
        public async override void ViewDidLoad()
        {
            //this.View.Frame = new CoreGraphics.CGRect (0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height - 64);
            base.ViewDidLoad();
            // LocalMedia represents the collection of tracks that we are sending to other Participants from our VideoClient.
            localMedia = new LocalMedia();
            this.NavigationController.NavigationBar.Translucent = false;
            this.NavigationController.NavigationBar.Hidden      = false;
            this.View.BackgroundColor = UIColor.FromRGB(0, 128, 64);
            messageLabel               = new UILabel();
            messageLabel.Frame         = new CGRect(10, 20, UIScreen.MainScreen.Bounds.Width, 20);
            messageLabel.TextColor     = UIColor.White;
            messageLabel.TextAlignment = UITextAlignment.Center;
            messageLabel.Font          = UIFont.SystemFontOfSize(12);
            View.Add(messageLabel);

            connectionLabel               = new UILabel();
            connectionLabel.Frame         = new CGRect(10, messageLabel.Frame.GetMaxY() + 100, UIScreen.MainScreen.Bounds.Width, 30);
            connectionLabel.TextColor     = UIColor.White;
            connectionLabel.Text          = "Connecting...";
            connectionLabel.TextAlignment = UITextAlignment.Center;
            connectionLabel.Font          = UIFont.SystemFontOfSize(16);
            View.Add(connectionLabel);

            micButton       = new UIButton();
            micButton.Frame = new CGRect(10, UIScreen.MainScreen.Bounds.Height - 64 - 40, 80, 40);
            micButton.SetTitle("Mute", UIControlState.Normal);
            micButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            micButton.BackgroundColor = UIColor.FromRGB(226, 29, 37);
            micButton.Font            = UIFont.SystemFontOfSize(12);
            View.Add(micButton);

            disconnectButton       = new UIButton();
            disconnectButton.Frame = new CGRect(UIScreen.MainScreen.Bounds.Width / 2 - 20, messageLabel.Frame.GetMaxY() + 20, 40, 40);
            disconnectButton.SetImage(UIImage.FromFile("HangupCall.png"), UIControlState.Normal);
            View.Add(disconnectButton);

            previewView                 = new UIView();
            previewView.Frame           = new CGRect(UIScreen.MainScreen.Bounds.Width - 160, UIScreen.MainScreen.Bounds.Height - 64 - 200, 150, 190);
            previewView.BackgroundColor = UIColor.Clear;
            View.Add(previewView);

            micButton.TouchUpInside += MicButton_TouchUpInside;
            // Wire up event handlers for VideoRoomDelegate
            // Purposefully wiring up every event.
            // Should Dispose of these.
            roomDelegate = new VideoRoomDelegate();
            roomDelegate.OnDidConnectToRoom        += HandleOnDidConnectToRoom;
            roomDelegate.OnDisconnectedWithError   += HandleOnDisconnectedWithError;
            roomDelegate.OnRoomFailedToConnect     += HandleOnRoomFailedToConnect;
            roomDelegate.OnParticipantDidConnect   += HandleOnParticipantDidConnect;
            roomDelegate.OnParticipantDisconnected += HandleOnParticipantDidConnect;

            // Wire up event handlers for VideoParticipantDelegate
            // Purposefully wiring up every event.
            // Should Dispose of these.
            participantDelegate = new VideoParticipantDelegate();
            participantDelegate.OnAddedVideoTrack   += HandleOnAddedVideoTrack;
            participantDelegate.OnRemovedVideoTrack += HandleOnRemovedVideoTrack;
            participantDelegate.OnAddedAudioTrack   += HandleOnAddedAudioTrack;
            participantDelegate.OnRemovedAudioTrack += HandleOnRemovedAudioTrack;
            participantDelegate.OnEnabledTrack      += HandleOnEnabledTrack;
            participantDelegate.OnDisabledTrack     += HandleOnDisabledTrack;

            if (IsSimulator)
            {
                //previewView.RemoveFromSuperview ();
            }
            else
            {
                // Preview our local camera track in the local video preview view.
                StartPreview();
            }
            // Disconnect and mic button will be displayed when client is connected to a room.
            disconnectButton.Hidden = false;
            micButton.Hidden        = false;

            if (accessToken == null)
            {
                LogMessage("Fetching an access token.");

                try {
                    var token = await Utils.GetTokenAsync(TokenUrl);

                    if (token != null)
                    {
                        accessToken = token;
                        DoConnect();
                    }
                    else
                    {
                        LogMessage("Error retrieving the access token.");
                        ShowRoomUI(false);
                    }
                } catch (Exception e) {
                    LogMessage($"Exception thrown when fetching access token: {e}");
                }
            }
            else
            {
                DoConnect();
            }

            // Should dispose of this.
            //roomTextField.ShouldReturn += (textField) => { ConnectButtonPressed (textField); return true; };
        }
		public override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);
			ContentView = R.layout.activity_advanced_camera_capturer;

			localMedia = LocalMedia.create(this);
			videoView = (VideoView) findViewById(R.id.video_view);
			toggleFlashButton = (Button) findViewById(R.id.toggle_flash_button);
			takePictureButton = (Button) findViewById(R.id.take_picture_button);
			pictureImageView = (ImageView) LayoutInflater.inflate(R.layout.picture_image_view, null);
			pictureDialog = (new AlertDialog.Builder(this)).setView(pictureImageView).setTitle(null).setPositiveButton([email protected], new OnClickListenerAnonymousInnerClassHelper(this))
				   .create();

			if (!checkPermissionForCamera())
			{
				requestPermissionForCamera();
			}
			else
			{
				addCameraVideo();
			}
		}
Example #23
0
 public void DidAddVideoTrack(LocalMedia media, VideoTrack videoTrack)
 {
     Console.WriteLine("Local video track added: {0}", videoTrack);
 }
		protected internal override void onDestroy()
		{
			if (localMedia != null)
			{
				if (screenVideoTrack != null)
				{
					localMedia.removeVideoTrack(screenVideoTrack);
				}
				localMedia.release();
				localMedia = null;
			}
			base.onDestroy();
		}