// case1: 当mediaSource为null,newPlayRange不为null时只改变入出点。 // case2: 当mediaSource不为null,newPlayRange为null时等长替换媒体源。 // case3: 当mediaSource不为null,newPlayRange不为null时变长替换媒体源。 private void ChangeMediaSourceInternal(IPlayItem playItem, IMediaSource mediaSource, PlayRange?newPlayRange) { //if (_playlist.IsLocked(playItem)) throw new PlayItemLockedException(); if (mediaSource == null && newPlayRange == null) { return; } if (mediaSource == null && newPlayRange.Value == playItem.PlayRange) { return; } if (newPlayRange != null && (playItem.ScheduleMode == PlayScheduleMode.Timing || playItem.ScheduleMode == PlayScheduleMode.TimingBreak)) { //_playlist.ValidateTimeRange(playItem.StartTime, newPlayRange.Value.Duration, playItem); ValidateTimeRange(playItem.StartTime, newPlayRange.Value.Duration, playItem); } PlayRange playRange = newPlayRange ?? new PlayRange(TimeSpan.Zero, playItem.CalculatedPlayDuration /*playItem.PlayRange.Duration*/); if (mediaSource == null) { mediaSource = playItem.MediaSource; //.Clone(); } var newPlaySource = new PlaySource(mediaSource, playRange, playItem.CGItems); IPlayItem newPlayItem = null; switch (playItem.ScheduleMode) { case PlayScheduleMode.Timing: newPlayItem = (IPlayItem)PlaybillItem.Timing(newPlaySource, playItem.StartTime); break; case PlayScheduleMode.TimingBreak: newPlayItem = (IPlayItem)PlaybillItem.TimingBreak(newPlaySource, playItem.StartTime); break; case PlayScheduleMode.Auto: newPlayItem = new AutoPlayItem(PlaybillItem.Auto(newPlaySource)); break; } var segment = this.FindSegment(playItem); DateTime startTime = segment.StartTime; int beginIndex = segment.BeginIndex; DateTime stopTime = segment.StopTime; int endIndex = segment.EndIndex; Rebuild(startTime, stopTime, beginIndex, endIndex, (items) => { var i = items.FindIndex(si => si.PlayItem == playItem); items[i] = new ScheduleItem(newPlayItem); }); }
internal void ChangePlayRange(IPlayItem playItem, PlayRange newRange) { int index = _playItems.IndexOf(playItem); if (index < 0) { throw new ArgumentException(); } IPlayItem newPlayItem = null; if (playItem.ScheduleMode != PlayScheduleMode.Auto) { if (newRange.Duration > playItem.PlayRange.Duration) { var newStopTime = playItem.StartTime.Add(newRange.Duration); if (this.HasTimingConflict(playItem.StartTime, newStopTime, playItem)) { throw new InvalidOperationException(); } } newPlayItem = (IPlayItem)((TimingPlaybillItem)playItem).Clone(newRange); } else { newPlayItem = new AutoPlayItem(((AutoPlaybillItem)playItem.PlaybillItem).Clone(newRange)); } _playItems[index] = newPlayItem; this.IsDirty = true; }
public void ForcePlay(IPlayItem currentItem, IPlayItem forcedItem) { this.Delete(forcedItem); DateTime stopTime; int beginIndex; var startTime = DateTime.Now.AddSeconds(1.0); var currentIndex = _playlist.FindIndex(i => i.PlayItem == currentItem); beginIndex = currentIndex + 1; Tuple <ScheduleItem, int> temp = FindFirstTiming(beginIndex, (i) => true); int endIndex; if (temp.Item1 != null) { stopTime = temp.Item1.StartTime; endIndex = temp.Item2 - 1; } else { stopTime = DateTime.MaxValue; endIndex = _playlist.Count - 1; } // 调整当前项的播放时长(入出点) // 复制当前项,并调整时长。 var startOffset = startTime.Subtract(currentItem.StartTime); var newRange = new PlayRange(currentItem.CalculatedPlayRange.StartPosition + startOffset, currentItem.CalculatedPlayRange.Duration - startOffset); var copyItem = new AutoPlayItem(new AutoPlaybillItem(currentItem.PlaybillItem.PlaySource.Clone(newRange))); //if (segment.Head == null) //{ // startTime = segment.StartTime; // beginIndex = segment.BeginIndex; //} //else //{ // startTime = segment.Head.CalculatedStopTime; // beginIndex = segment.BeginIndex + 1; //} //stopTime = segment.StopTime; //endIndex = segment.EndIndex; this.Rebuild(startTime, stopTime, beginIndex, endIndex, (items) => { // 插入复制项和forcedItem。 items.Insert(0, new ScheduleItem(copyItem)); items.Insert(0, new ScheduleItem(forcedItem)); }); }
internal static AutoPlayItem CreateAutoPadding(DateTime startTime, TimeSpan duration) { AutoPlaybillItem billItem = AutoPlaybillItem.CreateAutoPadding(duration); AutoPlayItem playItem = new AutoPlayItem(billItem); playItem.StartTime = startTime; return(playItem); }
public void Split(TimeSpan duration, out IPlayItem first, out IPlayItem second) { PlayRange firstRange, secondRange; FCSPlayout.Domain.PlayRange.Split(this.PlayRange, duration, out firstRange, out secondRange); first = new AutoPlayItem(this.PlaybillItem.Clone(firstRange), firstRange); second = new AutoPlayItem(this.PlaybillItem.Clone(secondRange), secondRange); }
internal void ChangeTimingToAuto(IPlayItem playItem) { var index = _playItems.IndexOf(playItem); if (index < 0) { throw new InvalidOperationException(); } //Debug.Assert(); var newPlayItem = new AutoPlayItem(AutoPlaybillItem.Auto(playItem.PlaybillItem.PlaySource)); _playItems[index] = newPlayItem; this.IsDirty = true; }
internal void ChangeSource(IPlayItem playItem, IMediaSource newSource, PlayRange?newRange) { int index = _playItems.IndexOf(playItem); if (index < 0) { throw new ArgumentException(); } IPlayItem newPlayItem = null; if (newRange != null && playItem.ScheduleMode != PlayScheduleMode.Auto) { if (newRange.Value.Duration > playItem.PlayRange.Duration) { var newStopTime = playItem.StartTime.Add(newRange.Value.Duration); if (this.HasTimingConflict(playItem.StartTime, newStopTime, playItem)) { throw new InvalidOperationException(); } } } else { } newRange = newRange == null ? new PlayRange(TimeSpan.Zero, playItem.CalculatedPlayDuration) : newRange.Value; var newPlaySource = new PlaySource(newSource, newRange.Value, playItem.PlaybillItem.PlaySource.CGItems); switch (playItem.ScheduleMode) { case PlayScheduleMode.Auto: newPlayItem = new AutoPlayItem(AutoPlaybillItem.Auto(newPlaySource)); break; case PlayScheduleMode.Timing: newPlayItem = (IPlayItem)TimingPlaybillItem.Timing(newPlaySource, playItem.StartTime); break; case PlayScheduleMode.TimingBreak: newPlayItem = (IPlayItem)TimingPlaybillItem.TimingBreak(newPlaySource, playItem.StartTime); break; } _playItems[index] = newPlayItem; this.IsDirty = true; }
/// <summary> /// 把定时播或定时插播改为顺播。 /// </summary> /// <param name="playItem"></param> private void ChangeToAutoScheduleInternal(IPlayItem playItem) { Debug.Assert(playItem.ScheduleMode == PlayScheduleMode.Timing || playItem.ScheduleMode == PlayScheduleMode.TimingBreak); //if (_playlist.IsLocked(playItem)) throw new PlayItemLockedException(); var prevTuple = this.FindLastTiming(i => i.StartTime < playItem.StartTime); DateTime startTime, stopTime; int beginIndex, endIndex; if (prevTuple.Item2 == -1) { startTime = _playlist[0].StartTime; beginIndex = 0; } else { startTime = prevTuple.Item1.CalculatedStopTime; beginIndex = prevTuple.Item2 + 1; } var nextTuple = this.FindFirstTiming(beginIndex, i => i.StartTime > playItem.StartTime); if (nextTuple.Item2 == -1) { stopTime = DateTime.MaxValue; endIndex = _playlist.Count - 1; } else { stopTime = nextTuple.Item1.StartTime; endIndex = nextTuple.Item2 - 1; } var playSource = ((PlaybillItem)playItem.PlaybillItem).PlaySource.Clone(); var newAutoItem = new AutoPlayItem(PlaybillItem.Auto(playSource)); Rebuild(startTime, stopTime, beginIndex, endIndex, (items) => { var i = items.FindIndex(si => si.PlayItem == playItem); items[i] = new ScheduleItem(newAutoItem); }); }
public void Append(IList <ScheduleItem> playItems) { if (playItems.Count == 0) { return; } var itemStartTime = playItems[0].StartTime; var prevTuple = this.FindLastTiming(i => i.StartTime <= itemStartTime); int beginIndex; if (prevTuple.Item2 == -1) { beginIndex = 0; } else { beginIndex = prevTuple.Item2; } while (beginIndex < _playlist.Count) { if (_playlist[beginIndex].StartTime >= itemStartTime) { break; } beginIndex++; } if (beginIndex == _playlist.Count) { if (_playlist.Count == 0) { var playlistStartTime = GetPlaylistStartTime(); // _playlist.GetStartTime(); if (playlistStartTime != null) { TimeSpan duration = itemStartTime.Subtract(playlistStartTime.Value); if (duration > TimeSpan.Zero) { var autoPadding = new ScheduleItem(AutoPlayItem.CreateAutoPadding(playlistStartTime.Value, duration)); var newItems = new List <ScheduleItem>(); newItems.Add(autoPadding); newItems.AddRange(playItems); playItems = newItems; } else { } } else //playlistStartTime == null { } } else { var lastStopTime = _playlist[_playlist.Count - 1].CalculatedStopTime; TimeSpan duration = itemStartTime.Subtract(lastStopTime); if (duration > TimeSpan.Zero) { var autoPadding = new ScheduleItem(AutoPlayItem.CreateAutoPadding(lastStopTime, duration)); var newItems = new List <ScheduleItem>(); newItems.Add(autoPadding); newItems.AddRange(playItems); playItems = newItems; } else { } } } //_playlist.Update(beginIndex, _playlist.Count - beginIndex, playItems); UpdatePlaylist(beginIndex, _playlist.Count - beginIndex, playItems); }
private ScheduleItem CreateAutoPadding(DateTime startTime, TimeSpan duration) { return(new ScheduleItem(AutoPlayItem.CreateAutoPadding(startTime, duration))); }
/// <summary> /// 把指定的顺播上移一个位置。 /// </summary> /// <param name="playItem"></param> public void MoveUp(IPlayItem playItem) { Debug.Assert(playItem.ScheduleMode == PlayScheduleMode.Auto); //if (_playlist.IsLocked(playItem)) throw new PlayItemLockedException(); if (_playlist[0] == playItem) { return; } //var index = _playlist.FindFirstIndex(i => i == playItem); var index = _playlist.FindIndex(i => i.PlayItem == playItem); if (index == -1) { throw new ArgumentException(); } if (index >= 2) { var newPrevItem = _playlist[index - 2]; //Reorder(newPrevItem, playItem); Reorder(newPrevItem.PlayItem, playItem); } else { Debug.Assert(index == 1); var oldPrevItem = _playlist[0]; if (oldPrevItem.ScheduleMode == PlayScheduleMode.Timing || oldPrevItem.ScheduleMode == PlayScheduleMode.TimingBreak) { return; } var playSource = new PlaySource(playItem.MediaSource /*.Clone()*/, playItem.PlayRange, playItem.CGItems); var newAutoItem = new AutoPlayItem(PlaybillItem.Auto(playSource)); var nextTuple = this.FindFirstTiming(index + 1, (i) => true); DateTime startTime = oldPrevItem.StartTime; int beginIndex = 0; DateTime stopTime; int endIndex; if (nextTuple.Item2 == -1) { stopTime = DateTime.MaxValue; endIndex = _playlist.Count - 1; } else { stopTime = nextTuple.Item1.StartTime; endIndex = nextTuple.Item2 - 1; } this.Rebuild(startTime, stopTime, beginIndex, endIndex, (items) => { items.RemoveAt(1); items.Insert(0, new ScheduleItem(newAutoItem)); }); } }
internal ScheduleItem Merge(ScheduleItem autoItem) { return(new ScheduleItem(AutoPlayItem.Merge(_playItem, autoItem._playItem))); }
internal bool CanMerge(ScheduleItem autoItem) { return(AutoPlayItem.CanMerge(_playItem, autoItem._playItem)); }