private void LoadVideoFrames() { double startTime = 0; double endTime = 0; int videoFrameCount = 0; startTime = VideoStartTime; endTime = VideoEndTime; videoFrameCount = VideoFrameCount; if(startTime == endTime) videoFrameCount = 1; if(endTime < startTime) { m_frames.Clear(); return; } if(m_lastStartTime == startTime && m_lastEndTime == endTime && videoFrameCount == m_lastFrameCount) return; m_lastStartTime = startTime; m_lastEndTime = endTime; m_lastFrameCount = videoFrameCount; m_cancelLoadFrames = true; double timeIncrement = (endTime - startTime)/videoFrameCount; var times = new List<TimeSpan>(); double sec = startTime; for(int i = 0; i < videoFrameCount; i++) { times.Add(TimeSpan.FromSeconds(sec)); sec += timeIncrement; } m_mediaDetector.Dispatcher.BeginInvoke((Action) delegate { m_cancelLoadFrames = false; Dispatcher.Invoke((Action) (() => m_frames.Clear())); for(int i = 0; i < times.Count; i++) { if(m_cancelLoadFrames) return; var frame = new VideoFrame(m_mediaDetector.GetImage(times[i]), times[i]); Dispatcher.Invoke((Action) (() => m_frames.Add(frame))); } var videoframe = new VideoFrame(m_mediaDetector.GetImage(TimeSpan.FromSeconds(endTime)), TimeSpan.FromSeconds(endTime)); Dispatcher.Invoke((Action) (() => m_frames.Add(videoframe))); m_cancelLoadFrames = false; }); }
private void LoadVideoFrames() { double startTime = 0; double endTime = 0; int videoFrameCount = 0; startTime = VideoStartTime; endTime = VideoEndTime; videoFrameCount = VideoFrameCount; if (startTime == endTime) { videoFrameCount = 1; } if (endTime < startTime) { m_frames.Clear(); return; } if (m_lastStartTime == startTime && m_lastEndTime == endTime && videoFrameCount == m_lastFrameCount) { return; } m_lastStartTime = startTime; m_lastEndTime = endTime; m_lastFrameCount = videoFrameCount; m_cancelLoadFrames = true; double timeIncrement = (endTime - startTime) / videoFrameCount; var times = new List <TimeSpan>(); double sec = startTime; for (int i = 0; i < videoFrameCount; i++) { times.Add(TimeSpan.FromSeconds(sec)); sec += timeIncrement; } m_mediaDetector.Dispatcher.BeginInvoke((Action) delegate { m_cancelLoadFrames = false; Dispatcher.Invoke((Action)(() => m_frames.Clear())); for (int i = 0; i < times.Count; i++) { if (m_cancelLoadFrames) { return; } var frame = new VideoFrame(m_mediaDetector.GetImage(times[i]), times[i]); Dispatcher.Invoke((Action)(() => m_frames.Add(frame))); } var videoframe = new VideoFrame(m_mediaDetector.GetImage(TimeSpan.FromSeconds(endTime)), TimeSpan.FromSeconds(endTime)); Dispatcher.Invoke((Action)(() => m_frames.Add(videoframe))); m_cancelLoadFrames = false; }); }