Exemple #1
0
        // Albert, 2012-12-28: TODO: Use a parameter of type PlayerChoice instead of directly referring to the slot index
        public IChannel GetChannel(int slotIndex)
        {
            if (TimeshiftControl == null)
            {
                return(null);
            }

            return(TimeshiftControl.GetChannel(GetMatchingSlotIndex(slotIndex)));
        }
Exemple #2
0
        public async Task <bool> StartTimeshiftAsync(int slotIndex, IChannel channel)
        {
            if (TimeshiftControl == null || channel == null)
            {
                return(false);
            }

            ServiceRegistration.Get <ILogger>().Debug("SlimTvHandler: StartTimeshift slot {0} for channel '{1}'", slotIndex, channel.Name);

            int newSlotIndex = GetMatchingSlotIndex(slotIndex);

            if (_slotContexes[newSlotIndex].Channel != null && _slotContexes[newSlotIndex].Channel.MediaType != channel.MediaType)
            {
                // Switching between TV and radio - must close old player and start brand new one
                IPlayerContext playerContext = existingPlayerContext(newSlotIndex);
                if (playerContext == null)
                {
                    return(false);
                }
                playerContext.Close();
                await StopTimeshiftAsync(newSlotIndex);
            }
            var result = await TimeshiftControl.StartTimeshiftAsync(newSlotIndex, channel);

            IList <MultipleMediaItemAspect> pras;
            MediaItem timeshiftMediaItem = result.Result;

            if (result.Success && timeshiftMediaItem != null && MediaItemAspect.TryGetAspects(timeshiftMediaItem.Aspects, ProviderResourceAspect.Metadata, out pras))
            {
                string newAccessorPath = (string)pras[0].GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH);

                // if slot was empty, start a new player
                if (_slotContexes[newSlotIndex].AccessorPath == null)
                {
                    AddOrUpdateTimeshiftContext(timeshiftMediaItem as LiveTvMediaItem, channel);
                    PlayerContextConcurrencyMode playMode = GetMatchingPlayMode();
                    await PlayItemsModel.PlayOrEnqueueItem(timeshiftMediaItem, true, playMode);
                }
                else
                {
                    try
                    {
                        _slotContexes[newSlotIndex].CardChanging = true;
                        UpdateExistingMediaItem(timeshiftMediaItem, newSlotIndex);
                    }
                    finally
                    {
                        _slotContexes[newSlotIndex].CardChanging = false;
                    }
                }
                _slotContexes[newSlotIndex].AccessorPath = newAccessorPath;
                _slotContexes[newSlotIndex].Channel      = channel;
            }
            return(result.Success);
        }
Exemple #3
0
        public async Task <bool> StopTimeshiftAsync(int slotIndex)
        {
            if (TimeshiftControl == null)
            {
                return(false);
            }

            _slotContexes[slotIndex].AccessorPath = null;
            _slotContexes[slotIndex].Channel      = null;

            return(await TimeshiftControl.StopTimeshiftAsync(slotIndex));
        }
Exemple #4
0
        public bool StopTimeshift(int slotIndex)
        {
            if (TimeshiftControl == null)
            {
                return(false);
            }

            _slotContexes[slotIndex].AccessorPath = null;
            _slotContexes[slotIndex].Channel      = null;

            return(TimeshiftControl.StopTimeshift(slotIndex));
        }
Exemple #5
0
        internal static async Task <bool> StopTimeshiftAsync(IOwinContext context, int id, string userName)
        {
            if (!CLIENT_CHANNELS.TryRemove(userName, out ChannelInfo channel))
            {
                return(false);
            }

            if (channel != null && !CLIENT_CHANNELS.Any(c => c.Value?.ChannelId == channel.ChannelId))
            {
                if (!(await TimeshiftControl.StopTimeshiftAsync(channel.UserName, channel.SlotIndex).ConfigureAwait(false)))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #6
0
        public bool StartTimeshift(int slotIndex, IChannel channel)
        {
            if (TimeshiftControl == null || channel == null)
            {
                return(false);
            }

            ServiceRegistration.Get <ILogger>().Debug("SlimTvHandler: StartTimeshift slot {0} for channel '{1}'", slotIndex, channel.Name);

            int       newSlotIndex = GetMatchingSlotIndex(slotIndex);
            MediaItem timeshiftMediaItem;
            bool      result = TimeshiftControl.StartTimeshift(newSlotIndex, channel, out timeshiftMediaItem);
            IList <MultipleMediaItemAspect> pras;

            if (result && timeshiftMediaItem != null && MediaItemAspect.TryGetAspects(timeshiftMediaItem.Aspects, ProviderResourceAspect.Metadata, out pras))
            {
                string newAccessorPath = (string)pras[0].GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH);

                // if slot was empty, start a new player
                if (_slotContexes[newSlotIndex].AccessorPath == null)
                {
                    AddOrUpdateTimeshiftContext(timeshiftMediaItem as LiveTvMediaItem, channel);
                    PlayerContextConcurrencyMode playMode = GetMatchingPlayMode();
                    PlayItemsModel.PlayOrEnqueueItem(timeshiftMediaItem, true, playMode);
                }
                else
                {
                    try
                    {
                        _slotContexes[newSlotIndex].CardChanging = true;
                        UpdateExistingMediaItem(timeshiftMediaItem);
                    }
                    finally
                    {
                        _slotContexes[newSlotIndex].CardChanging = false;
                    }
                }
                _slotContexes[newSlotIndex].AccessorPath = newAccessorPath;
                _slotContexes[newSlotIndex].Channel      = channel;
            }

            return(result);
        }
        public bool StartTimeshift(int slotIndex, IChannel channel)
        {
            if (TimeshiftControl == null || channel == null)
            {
                return(false);
            }

            int       newSlotIndex = GetMatchingSlotIndex(slotIndex);
            MediaItem timeshiftMediaItem;
            bool      result = TimeshiftControl.StartTimeshift(newSlotIndex, channel, out timeshiftMediaItem);

            if (result && timeshiftMediaItem != null)
            {
                string newAccessorPath =
                    (string)timeshiftMediaItem.Aspects[ProviderResourceAspect.ASPECT_ID].GetAttributeValue(
                        ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH);

                // if slot was empty, start a new player
                if (_slotContexes[newSlotIndex].AccessorPath == null)
                {
                    AddTimeshiftContext(timeshiftMediaItem as LiveTvMediaItem, channel);
                    PlayerContextConcurrencyMode playMode = GetMatchingPlayMode();
                    PlayItemsModel.PlayOrEnqueueItem(timeshiftMediaItem, true, playMode);
                }
                else
                {
                    try
                    {
                        _slotContexes[newSlotIndex].CardChanging = true;
                        UpdateExistingMediaItem(timeshiftMediaItem);
                    }
                    finally
                    {
                        _slotContexes[newSlotIndex].CardChanging = false;
                    }
                }
                _slotContexes[newSlotIndex].AccessorPath = newAccessorPath;
                _slotContexes[newSlotIndex].Channel      = channel;
            }

            return(result);
        }
Exemple #8
0
 // Note: the slotIndex represents the server side stream, which is not related to the PlayerSlot.
 public IChannel GetChannel(int slotIndex)
 {
     return(TimeshiftControl?.GetChannel(GetMatchingSlotIndex(slotIndex)));
 }
Exemple #9
0
        internal static async Task <MediaItem> StartTimeshiftAsync(IOwinContext context, int id, string userName)
        {
            var channel = await GetChannelAsync(id);

            if (channel == null)
            {
                return(null);
            }

            var client = CLIENT_CHANNELS.FirstOrDefault(c => c.Value.ChannelId == id);

            if (client.Value?.MediaItem != null)
            {
                //Check if already streaming
                if (client.Key == userName)
                {
                    return(client.Value.MediaItem);
                }

                //Use same stream url as other channel
                if (!CLIENT_CHANNELS.TryAdd(userName, client.Value))
                {
                    return(null);
                }
                else
                {
                    return(client.Value.MediaItem);
                }
            }

            var freeSlot = GetFreeSlot();

            if (freeSlot == null)
            {
                return(null);
            }

            var item = await TimeshiftControl.StartTimeshiftAsync(userName, freeSlot.Value, channel);

            if (!item.Success)
            {
                return(null);
            }

            //Initiate channel cache
            ChannelInfo newChannel = new ChannelInfo
            {
                SlotIndex = freeSlot.Value,
                ChannelId = id,
                MediaItem = item.Result,
                UserName  = userName
            };

            if (!CLIENT_CHANNELS.TryAdd(userName, newChannel))
            {
                await TimeshiftControl.StopTimeshiftAsync(userName, freeSlot.Value);

                return(null);
            }

            return(item.Result);
        }