/// <summary>
        /// Handles the Tick event of the Timer control.
        /// It handles the forward/rewind of the media.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (this.currentSkipDirection == 0)
            {
                return;
            }

            bool add = this.currentSkipDirection > 0;
            long newSkipDirection = 1;

            TimeCode currentTimeCode    = TimeCode.FromTimeSpan(this.Player.Position, this.currentSmpteFrameRate);
            long     currentTotalFrames = currentTimeCode.TotalFrames;

            TimeCode frameTimeCode = TimeCode.FromFrames(newSkipDirection, this.currentSmpteFrameRate);

            currentTimeCode = add ? currentTimeCode.Add(frameTimeCode) : currentTimeCode.Subtract(frameTimeCode);
            newSkipDirection++;

            while (currentTimeCode.TotalFrames == currentTotalFrames)
            {
                frameTimeCode   = TimeCode.FromFrames(newSkipDirection, this.currentSmpteFrameRate);
                currentTimeCode = add ? currentTimeCode.Add(frameTimeCode) : currentTimeCode.Subtract(frameTimeCode);
                newSkipDirection++;
            }

            this.Player.Position = TimeSpan.FromSeconds(Math.Max(0, currentTimeCode.TotalSeconds));
            this.SetCurrentTime(this.Player.Position);
        }
Exemple #2
0
        public IEnumerable <Section> Merge(IEnumerable <Marker> markers)
        {
            List <Section> sections       = new List <Section>();
            Section        lastSection    = null;
            var            orderedMarkers = markers.OrderBy(p => p.Timecode);

            foreach (var marker in orderedMarkers)
            {
                var tc = new TimeCode(marker.Timecode, this.Settings.FrameRate);
                var framesPerSecond = new TimeCode(1.0, this.Settings.FrameRate).TotalFrames;
                if (lastSection == null || (tc.TotalFrames - lastSection.Out.TotalFrames) > framesPerSecond * this.Settings.SectionDurationSeconds)
                {
                    var section = new Section {
                        In = tc.Add(TimeCode.FromSeconds(0.0 - this.Settings.SectionDurationSeconds, this.Settings.FrameRate)), Out = tc.Add(TimeCode.FromSeconds(this.Settings.SectionDurationSeconds, this.Settings.FrameRate)),
                    };
                    sections.Add(section);
                    lastSection = section;
                }
                else
                {
                    lastSection.Out = tc.Add(TimeCode.FromSeconds(this.Settings.SectionDurationSeconds, this.Settings.FrameRate));
                }
            }
            return(sections);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            long     l      = (long)value;
            TimeCode offset = (TimeCode)parameter;
            var      ret    = offset.Add(TimeCode.FromSeconds((double)l / 1000.0, offset.FrameRate));

            return(ret.ToString());
        }
        /// <summary>
        /// Handles the Rewind/Forward of the <see cref="IAggregateMediaModel"/>.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void FrameRewindForwardTimerTick(object sender, EventArgs e)
        {
            if (this.currentSkipDirection == 0)
            {
                return;
            }

            bool add = this.currentSkipDirection > 0;
            long newSkipDirection = 1;

            TimeCode currentTimeCode    = TimeCode.FromTimeSpan(this.manifestMediaModel.Position, this.sequenceRegistry.CurrentSequenceModel.Duration.FrameRate);
            long     currentTotalFrames = currentTimeCode.TotalFrames;

            TimeCode frameTimeCode = TimeCode.FromFrames(newSkipDirection, this.sequenceRegistry.CurrentSequenceModel.Duration.FrameRate);

            currentTimeCode = add ? currentTimeCode.Add(frameTimeCode) : currentTimeCode.Subtract(frameTimeCode);
            newSkipDirection++;

            while (currentTimeCode.TotalFrames == currentTotalFrames)
            {
                frameTimeCode   = TimeCode.FromFrames(newSkipDirection, this.sequenceRegistry.CurrentSequenceModel.Duration.FrameRate);
                currentTimeCode = add ? currentTimeCode.Add(frameTimeCode) : currentTimeCode.Subtract(frameTimeCode);
                newSkipDirection++;
            }

            TimeSpan position = TimeSpan.FromSeconds(Math.Max(0, currentTimeCode.TotalSeconds));

            // Check if the playing mode is comment. If yes then don't allow to go forwar/backwar
            // beyond the comment Markin and MarkOut position.
            if (this.PlayerMode == PlayerMode.Comment && this.currentPlayingComment != null)
            {
                if (position.TotalSeconds < this.currentPlayingComment.MarkIn)
                {
                    position = TimeSpan.FromMilliseconds(this.currentPlayingComment.MarkIn.GetValueOrDefault() * 1000);
                }
                else if (position.TotalSeconds > this.currentPlayingComment.MarkOut)
                {
                    position = TimeSpan.FromMilliseconds(this.currentPlayingComment.MarkOut.GetValueOrDefault() * 1000);
                }
            }

            this.manifestMediaModel.Position = position;
            this.OnPositionUpdated(this, new PositionPayloadEventArgs(position));
        }