コード例 #1
0
        private void SyncAllNext_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(VideoFilePath))
            {
                if (!string.IsNullOrEmpty(SrtFilePath))
                {
                    UCPlayer1.Pause();
                    var currentIndex      = SubTitlesGrv.SelectedRows[0].Index;
                    var SelectedSubtitles = SubTitleItems[currentIndex];
                    var position          = UCPlayer1.Position;
                    var currentTime       = new TimeSpan((long)position);
                    var Shift             = currentTime - SelectedSubtitles.Start;
                    SubTitleItems.ShiftAllAfterIndex(Shift, currentIndex);
                    SubTitleItems.WriteToFile(SrtFilePath);
                    //Reload Video And Seek To Current Position
                    var currentPos = UCPlayer1.Position;
                    UCPlayer1.Stop();
                    UCPlayer1.Play(VideoFilePath);
                    UCPlayer1.Position = currentPos;
                    UCPlayer1.Pause();

                    MessageBox.Show("Sync Done", "DONE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(this, "Srt File Not Found", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Please Load File First", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
 private void MenuItem_UnloadBtn_Click(object sender, EventArgs e)
 {
     UCPlayer1.Stop();
     VideoFilePath = SrtFilePath = UCPlayer1.FilePath = null;
     //UCPlayer1.CurrentTime = UCPlayer1.TotalTime = "00:00:00,000";
     SubTitlesGrv.DataSource = null;
 }
コード例 #3
0
        private void MenuItem_Load_Click(object sender, EventArgs e)
        {
            UCPlayer1.Stop();
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = Settings.AllowedVideoTypes;
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                LoadVideo(ofd.FileName);
            }
        }
コード例 #4
0
        public void LoadVideo(string VideoPath, bool FromEvent = false)
        {
            Text = VideoFilePath = VideoPath;

            SrtFilePath = Path.Combine(Path.GetDirectoryName(VideoPath), Path.GetFileNameWithoutExtension(VideoPath) + ".srt");
            //Fill Grid
            if (File.Exists(SrtFilePath))
            {
                SubTitleItems = new List <SubTitleItem>();
                var      lines = System.IO.File.ReadAllLines(SrtFilePath, Encoding.Default);
                bool     ReadText = false;
                TimeSpan start = new TimeSpan(), end = new TimeSpan(), ts1, ts2;
                string   Text = "";
                foreach (var line in lines)
                {
                    if (IsTimeLine(line, out ts1, out ts2))
                    {
                        start    = ts1;
                        end      = ts2;
                        ReadText = true;
                    }
                    else if (IsSubtitleCounter(line) || string.IsNullOrEmpty(line))
                    {
                        if (!string.IsNullOrEmpty(Text))
                        {
                            SubTitleItems.Add(new SubTitleItem()
                            {
                                Start = start, End = end, Text = Text
                            });
                            ReadText = false;
                            Text     = "";
                        }
                    }
                    else if (ReadText)
                    {
                        Text += line + Environment.NewLine;
                    }
                }

                SubTitlesGrv.DataSource = SubTitleItems;
                if (!FromEvent)
                {
                    UCPlayer1.Play(VideoFilePath);
                }
            }
            else
            {
                UCPlayer1.FilePath = "";
                var result = MessageBox.Show(this, "Srt File Not Found, Want To Select It?", "ERROR", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Filter = "Srt File|*.srt|All Files|*.*";
                    if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        File.Copy(ofd.FileName, SrtFilePath);
                        if (!FromEvent)
                        {
                            LoadVideo(VideoFilePath);
                        }
                    }
                }
            }
        }