Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How to: Lock the Speaker's Video in a Meeting

[This is preliminary documentation and is subject to change.]

Describes how a Microsoft Lync 2013 Preview conversation presenter can lock the video stream of any other conversation participant so that all other participants cannot unpin and remove the video stream of the locked participant from the video gallery view.

It is useful to lock a participant’s video in a meeting when the participant is a primary speaker such as a lecturer. In this kind of scenario, the meeting may be composed of a number of students who have joined a class remotely and a teacher who gives the lecture in a classroom. The teacher would be in the role of meeting presenter and all students would be attendees. When the teacher’s video is locked, students can only see a video stream from the teacher. They cannot view or pin the video from other students. In addition, the video view on all Lync 2013 Preview conversation windows is set to the single-speaker view. The gallery view does not return until the teacher’s video stream has been unlocked.

Before running the code in this topic, an audio/video conversation with three or more participants must be active and you have obtained a Microsoft.Lync.Model.Conversation.Participant object from the Conversation.Participants collection. For information about starting an audio/video conversation, see How to: Start a Video Conversation

The following prerequisites must be met before locking or unlocking a participant video stream. These prerequisites are:

  • The conversation must be active.

  • The signed in user must be a presenter in the conversation.

    Verify that the signed in user is a presenter in the conversation by reading the Participant.Properties collection and obtaining the property value enumerated by ParticipantProperty.IsLeader.

  • The Microsoft.Lync.Model.Conversation.AudioVideo.AVModality must be connected.

    Verify the selected participant’s AVModality is connected by reading the Modality.State property of the modality. The value must be ModalityState.Connected.

  • The conversation must have at least three participants.

A participant video stream can be locked when the prerequisites are met. The participant’s webcam does not need to be turned on in order to lock the participant’s video stream. When the locked participant turns on the webcam, video will begin streaming to all participants.

Important note Important

In a conversation where there are multiple presenters, a presenter cannot unlock the video stream that is locked by another presenter. In this scenario, the BeginLockVideo(AsyncCallback, Object) method fails when called by all of the conversation presenters except the presenter who most recently locked a participant’s video stream.

Code example

The following example checks for the video locking or unlocking prerequisites and returns false if any prerequisite is not met.

        /// <summary>
        /// Returns true if video locking prerequisites have been met
        /// </summary>
        /// <param name="conversation">Conversation. The active conversation</param>
        /// <param name="participant">Participant. The paricipant whose video is to be locked</param>
        /// <returns></returns>
        private bool OkToManageParticipantVideo(Conversation conversation, Participant participant)
        {
            //Return to caller if local signed in user is not a conversation presenter.
            if (conversation.State != ConversationState.Active)
            {
                return false;
            }
            if ((bool)conversation.SelfParticipant.Properties[ParticipantProperty.IsLeader] == false)
            {
                return false;
            }
            if (conversation.Participants.Count < 3)
            {
                return false;
            }

            //Return to caller if the selected conversation participant has not connected the video modality
            if (((Modality)participant.Modalities[ModalityTypes.AudioVideo]).State != ModalityState.Connected)
            {
                return false;
            }
            if (!participant.CanInvoke(ParticipantAction.Lock))
            {
                return false;
            }
            return true;
        }

The Lync 2013 Preview API notifies you when you can lock or unlock the video stream of a conversation participant by invoking the Participant.ActionAvailabilityChanged event. When the ParticipantAction.Lock becomes available, you can lock the video stream of the participant object that raised the ActionAvailabilityChanged event. The Lync 2013 Preview API does not cache the current availability of the lock action. You should cache the availability of the action by declaring a class data structure that contains a row for each participant. The first column should be a reference to a Participant object and the second column should contain a Boolean value that is true when video lock is available. Your cache should be updated in the ActionAvailabilityChanged event handler. Before attempting to lock or unlock a participant’s video, get the data structure row for the participant and read the Boolean value. If it is true, then you can lock the particpant’s video

Declare a data structure

The following example declares a dictionary that keeps the current availability of video locking for each conversation participant.

        /// <summary>
        /// Caches the availability of video locking on a participant
        /// </summary>
        Dictionary<Participant, Boolean> _VideoLockAvailability = new Dictionary<Participant, bool>();


Update the data structure in the ActionAvailabilityChanged event

        /// <summary>
        /// Invoked when the availability of an action on a participant changes. 
        /// </summary>
        /// <param name="sender">object. The Participant whose action has changed</param>
        /// <param name="e">ParticipantActionAvailabilityChangedEventArgs. The event state.</param>
        void Participant_ActionAvailabilityChanged(object sender, ParticipantActionAvailabilityChangedEventArgs e)
        {
            Participant p = (Participant)sender;
            if (e.Action == ParticipantAction.Lock)
            {
                if (!_VideoLockAvailability.ContainsKey(p))
                {
                    _VideoLockAvailability.Add(p, e.IsAvailable);
                }
                else
                {
                    _VideoLockAvailability.Remove(p);
                    _VideoLockAvailability.Add(p, e.IsAvailable);
                }
            }
        }


To lock or unlock the video stream of a participant, do the following:

  1. Meet the prerequisites for video stream locking.

  2. Get the locally cached availability of locking for the desired participant.

  3. Get the current video locked state of the participant by reading the Participant.Properties collection and obtaining the property value enumerated by ParticipantProperty.IsLocked.

  4. If the participant video is locked, call the Participant.BeginUnLockVideo method.

  5. If the participant video is not locked, call the Participant.BeginLockVideo method.

Important note Important

If the ParticipantCanInvoke(ParticipantAction) method returns true and the participant’s video is already locked by the local user, then the call to the Participant.BeginLockVideo method has no effect. In the same way, a call to Participant.BeginUnLockVideo method has no effect when the participant’s video is not locked.

Code example

The following example locks the video stream of a participant if it is unlocked and unlocks the video stream if it is locked.

        /// <summary>
        /// locks or unlocks the video stream of a conversation participant
        /// </summary>
        /// <param name="conversation">Conversation. The active conversation whose participan will be locked</param>
        /// <param name="participant">Participant. The participant selected to be locked or unlocked</param>
        private void LockParticipantVideo(Conversation conversation, Participant participant)
        {
            if (!OkToManageParticipantVideo(conversation, participant))
            {
                return;
            }
            Boolean canLock = false;
            if (_VideoLockAvailability.TryGetValue(participant, out canLock))
            {
                if (canLock == false)
                {
                    return;
                }
                if ((bool)participant.Properties[ParticipantProperty.IsLocked] == false)
                {
                    participant.BeginLockVideo((ar) =>
                    {
                        participant.EndLockVideo(ar);
                    }
                    , null);
                }
                else
                {
                    participant.BeginUnLockVideo((ar) =>
                    {
                        participant.EndUnLockVideo(ar);
                    }
                    , null);
                }
            }
        }

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.