Exemple #1
0
        public bool ResetSlot(int slotIndex, out IPlayerSlotController slotController)
        {
            slotController = null;
            if (slotIndex == PlayerManagerConsts.SECONDARY_SLOT && !_slots[PlayerManagerConsts.PRIMARY_SLOT].IsActive)
            {
                // This is the only invalid constellation because it is not allowed to have the secondary slot active while the primary slot is inactive
                return(false);
            }
            // We don't set a lock because the IsActive property must be set outside the lock. It is no very good solution
            // to avoid the lock completely but I'll risk it here. Concurrent accesses to the player manager should be avoided
            // by organizational means.
            PlayerSlotController psc = _slots[slotIndex];

            if (psc.IsActive)
            {
                psc.IsActive = false; // Must be done outside the lock
            }
            psc.IsActive    = true;
            psc.IsMuted     = _isMuted;
            psc.Volume      = _volume;
            psc.IsAudioSlot = false;
            if (AudioSlotIndex == -1)
            {
                AudioSlotIndex = slotIndex;
            }
            slotController = psc;
            return(true);
        }
        public void CloseSlot(IPlayerSlotController playerSlotController)
        {
            PlayerSlotController psc = playerSlotController as PlayerSlotController;

            if (psc == null)
            {
                return;
            }
            bool isAudio = psc.IsAudioSlot && !psc.IsClosed;
            PlayerSlotController nextPsc;

            lock (_syncObj)
            {
                int nextIndex = _slots.IndexOf(psc);
                _slots.Remove(psc);
                int numSlots = _slots.Count;
                nextIndex = numSlots == 0 ? 0 : (nextIndex + 1) % numSlots;
                nextPsc   = numSlots > nextIndex ? _slots[nextIndex] : null;
            }
            psc.Close_NoLock(); // Must be done outside the lock
            if (isAudio && nextPsc != null)
            {
                nextPsc.IsAudioSlot = true;
            }
        }
Exemple #3
0
 public IPlayer this[int slotIndex]
 {
     get
     {
         lock (_syncObj)
         {
             PlayerSlotController psc = GetPlayerSlotControllerInternal(slotIndex);
             if (psc == null)
             {
                 return(null);
             }
             return(psc.IsActive ? psc.CurrentPlayer : null);
         }
     }
 }
Exemple #4
0
        public void CloseSlot(IPlayerSlotController playerSlotController)
        {
            PlayerSlotController psc = playerSlotController as PlayerSlotController;

            if (psc == null)
            {
                return;
            }
            bool isAudio = psc.IsActive && psc.IsAudioSlot;

            psc.IsActive = false; // Must be done outside the lock
            CleanupSlotOrder();
            if (isAudio)
            {
                AudioSlotIndex = PlayerManagerConsts.PRIMARY_SLOT;
            }
        }
        public IPlayerSlotController OpenSlot()
        {
            // We don't set a lock because the IsActive property must be set outside the lock. It is no very good solution
            // to avoid the lock completely but I'll risk it here. Concurrent accesses to the player manager should be avoided
            // by organizational means.
            PlayerSlotController result = new PlayerSlotController(this)
            {
                IsMuted     = _isMuted,
                IsAudioSlot = false
            };

            if (AudioSlotController == null)
            {
                result.IsAudioSlot = true;
            }
            lock (SyncObj)
                _slots.Add(result);
            return(result);
        }
Exemple #6
0
 public void SwitchSlots()
 {
     lock (_syncObj)
     {
         if (!_slots[PlayerManagerConsts.SECONDARY_SLOT].IsActive)
         {
             // Don't move an inactive player slot to the primary slot index
             return;
         }
         PlayerSlotController tmp = _slots[PlayerManagerConsts.PRIMARY_SLOT];
         _slots[PlayerManagerConsts.PRIMARY_SLOT]   = _slots[PlayerManagerConsts.SECONDARY_SLOT];
         _slots[PlayerManagerConsts.SECONDARY_SLOT] = tmp;
         for (int i = 0; i < 2; i++)
         {
             _slots[i].SlotIndex = i;
         }
         // Audio slot index changes automatically as it is stored in the slot instance itself
         PlayerManagerMessaging.SendPlayerManagerPlayerMessage(PlayerManagerMessaging.MessageType.PlayerSlotsChanged);
     }
 }
 public IPlayerSlotController OpenSlot()
 {
   // We don't set a lock because the IsActive property must be set outside the lock. It is no very good solution
   // to avoid the lock completely but I'll risk it here. Concurrent accesses to the player manager should be avoided
   // by organizational means.
   PlayerSlotController result = new PlayerSlotController(this)
     {
         IsMuted = _isMuted,
         IsAudioSlot = false
     };
   if (AudioSlotController == null)
     result.IsAudioSlot = true;
   lock (SyncObj)
     _slots.Add(result);
   return result;
 }