示例#1
0
        public void AddAutoItem(IPlayItem playItem, IPlayItem prevItem)
        {
            Debug.Assert(playItem.PlaybillItem.ScheduleMode == PlayScheduleMode.Auto);

            if (_segments.IsEmpty)
            {
                if (_buildOption.RequireFirstTimingItem)
                {
                    throw new InvalidOperationException("第一个播放项必须是定时播。");
                }

                var newSegment = _segments.CreateSegment(_buildOption.PlayTimeRange.StartTime, playItem);
                _segments.AddLast(newSegment);
            }
            else
            {
                PlaylistSegment segment = prevItem != null?
                                          _segments.FindLastSegment((s) => s.Contains(prevItem)) : _segments.LastSegment;

                if (segment == null)
                {
                    throw new ArgumentException();
                }

                if (prevItem == null)
                {
                    segment.Add(playItem);
                }
                else
                {
                    segment.InsertAuto(playItem, prevItem);
                }
            }
        }
示例#2
0
        internal void Remove(PlaylistSegment segment)
        {
            var prevSegment = segment.Previous;

            if (prevSegment != null)
            {
                prevSegment.Next = segment.Next;
                if (prevSegment.Next == null)
                {
                    this.LastSegment = prevSegment;
                }
            }
            else
            {
                this.FirstSegment = segment.Next;
                if (this.FirstSegment == null)
                {
                    this.LastSegment = null;
                }
                else
                {
                    this.FirstSegment.Previous = null;
                }
            }
        }
示例#3
0
 internal void AddFirst(PlaylistSegment segment)
 {
     if (IsEmpty)
     {
         this.FirstSegment = this.LastSegment = segment;
     }
     else
     {
         segment.Next      = this.FirstSegment;
         this.FirstSegment = segment;
     }
 }
示例#4
0
        internal void InsertSegment(PlaylistSegment prevSegment, PlaylistSegment newSegment)
        {
            var oldNext = prevSegment.Next;

            prevSegment.Next = newSegment;
            newSegment.Next  = oldNext;

            if (this.LastSegment == prevSegment)
            {
                this.LastSegment = newSegment;
            }
        }
示例#5
0
        internal void MergeFrom(PlaylistSegment segment)
        {
            foreach (var item in segment._playItems)
            {
                if (item.ScheduleMode == PlayScheduleMode.Timing)
                {
                    throw new InvalidOperationException();
                }

                this._playItems.Add(item);
                this.IsDirty = true;
            }
        }
示例#6
0
        private PlaylistSegment FindSegment(IPlayItem playItem)
        {
            if (_playlist.Count == 0)
            {
                throw new InvalidOperationException();
            }

            //int currentIndex = _playlist.FindFirstIndex(i => i == playItem);
            int currentIndex = _playlist.FindIndex(i => i.PlayItem == playItem);

            if (currentIndex == -1)
            {
                throw new InvalidOperationException();
            }

            int prevIndex = _playlist.FindLastIndex(currentIndex, i => i.ScheduleMode == PlayScheduleMode.Timing && i.StartTime <= playItem.StartTime);

            PlaylistSegment segment = null;

            if (prevIndex == -1)
            {
                segment = new PlaylistSegment(_playlist[0].StartTime)
                {
                    BeginIndex = 0
                };
            }
            else
            {
                segment = new PlaylistSegment(_playlist[prevIndex])
                {
                    BeginIndex = prevIndex
                };
            }

            //int nextIndex = _playlist.FindFirstIndex(currentIndex + 1, i => i.PlaybillItem.ScheduleMode == PlayScheduleMode.Timing && i.StartTime > playItem.StartTime);
            int nextIndex = _playlist.FindIndex(currentIndex + 1, i => i.ScheduleMode == PlayScheduleMode.Timing && i.StartTime > playItem.StartTime);

            if (nextIndex == -1)
            {
                segment.EndIndex = _playlist.Count - 1;
                segment.StopTime = DateTime.MaxValue;
            }
            else
            {
                segment.EndIndex = nextIndex - 1;
                segment.StopTime = _playlist[nextIndex].StartTime;
            }

            return(segment);
        }
示例#7
0
        public PlaylistSegmentCollection(IList <IPlayItem> playItems, IPlaylistBuildOption buildOption)
        {
            _buildOption = buildOption;
            List <IPlayItem> items = new List <IPlayItem>();

            for (int i = 0; i < playItems.Count; i++)
            {
                var item = playItems[i];
                if (item.ScheduleMode == PlayScheduleMode.Timing)
                {
                    if (items.Count > 0)
                    {
                        PlaylistSegment segment = new PlaylistSegment(items);
                        AddLast(segment);
                        items.Clear();
                    }
                }

                items.Add(item);
            }

            if (items.Count > 0)
            {
                PlaylistSegment segment = new PlaylistSegment(items);
                AddLast(segment);
                items.Clear();
            }

            var seg = this.FirstSegment;

            while (seg != null)
            {
                seg.IsDirty = false;
                seg         = seg.Next;
            }
        }
示例#8
0
        internal void Add(IPlayItem playItem)
        {
            if (playItem.ScheduleMode == PlayScheduleMode.Timing)
            {
                // 只能添加到末尾。
                if (playItem.StartTime < this.StartTime)
                {
                    throw new InvalidOperationException("新加的定时播必须在现有定时播后面。");
                }

                if (this.HasTimingConflict(playItem.StartTime, playItem.CalculatedStopTime))
                {
                    throw new InvalidOperationException("新加的定时播与现有定时播或定时插播之间有时间冲突。");
                }

                if (this.Next != null && playItem.CalculatedStopTime > this.Next.StartTime)
                {
                    throw new InvalidOperationException("新加的定时播与现有定时播或定时插播之间有时间冲突。");
                }


                List <IPlayItem> newSegmentItems = new List <IPlayItem>();
                newSegmentItems.Add(playItem);
                for (int i = _playItems.Count; i >= 0; i--)
                {
                    var temp = _playItems[i];
                    if (temp.ScheduleMode == PlayScheduleMode.TimingBreak)
                    {
                        if (temp.StartTime < playItem.StartTime)
                        {
                            break;
                        }

                        _playItems.RemoveAt(i);
                        newSegmentItems.Add(temp);
                    }
                }

                var nextSegment = new PlaylistSegment(newSegmentItems)
                {
                    IsDirty = true
                };
                nextSegment.Next = this.Next;
                this.Next        = nextSegment;
                this.IsDirty     = true;
                return;
            }

            if (playItem.ScheduleMode == PlayScheduleMode.TimingBreak)
            {
                //if (playItem.StartTime < this.StartTime)
                //{
                //    throw new InvalidOperationException("新加的定时播必须在现有定时播后面。");
                //}

                if (this.HasTimingConflict(playItem.StartTime, playItem.CalculatedStopTime))
                {
                    throw new InvalidOperationException("新加的定时插播与现有定时播或定时插播之间有时间冲突。");
                }

                if (this.Next != null && playItem.CalculatedStopTime > this.Next.StartTime)
                {
                    throw new InvalidOperationException("新加的定时插播与现有定时播或定时插播之间有时间冲突。");
                }
            }

            _playItems.Add(playItem);
            this.IsDirty = true;
        }