Пример #1
0
        private void openVideoAudioFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog opnFileDlg = new OpenFileDialog();

            opnFileDlg.Multiselect = true;
            opnFileDlg.Filter      = "(mp3,wav,mp4,mov,wmv,mpg,avi,3gp,flv)|*.mp3;*.wav;*.mp4;*.3gp;*.avi;*.mov;*.flv;*.wmv;*.mpg|all files|*.*";
            if (opnFileDlg.ShowDialog() == DialogResult.OK)
            {
                string FileName = opnFileDlg.FileName;
                axWindowsMediaPlayer1.settings.autoStart = true;
                axWindowsMediaPlayer1.URL = FileName;
                axWindowsMediaPlayer1.Ctlcontrols.next();
                //axWindowsMediaPlayer1.Ctlcontrols.currentPosition = 0.1;
                if (!captionsLoaded)
                {
                    vttpath = FileName.Substring(0, FileName.LastIndexOf(".")) + ".vtt";
                    if (File.Exists(vttpath))
                    {
                        openClosedCaptionsFile(vttpath);
                    }
                    else
                    {
                        captionsList.Items.Clear();
                        curCaption     = new captionInfo(0);
                        captionsLoaded = true;
                        captionsList.Items.Add(curCaption);
                        captionsList.SelectedIndex = 0;
                        editCurCaption();
                    }
                }
                mediaLoaded = true;
            }
        }
Пример #2
0
 private void captionsList_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!changingCaptionIndex)
     {
         updateCurCaption();
         if (captionsList.SelectedIndex != -1)
         {
             curCaption = (captionInfo)captionsList.Items[captionsList.SelectedIndex];
             axWindowsMediaPlayer1.Ctlcontrols.currentPosition = curCaption.start;
             editCurCaption();
         }
     }
 }
Пример #3
0
        private int findCaptionIndexForTime(double time)
        {
            //captionsList.Items.
            int n = 0;

            while (n < captionsList.Items.Count)
            {
                captionInfo test = (captionInfo)captionsList.Items[n];
                if ((test.start <= time) && (test.start + test.length > time))
                {
                    return(n);
                }
                n++;
            }
            return(-1);
        }
Пример #4
0
        private void StartStop()
        {
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused)
            {
                //Start a new caption
                changingCaptionIndex = true;
                curCaption.caption   = captionEdt.Text;
                if (captionsList.SelectedItem != null)
                {
                    captionsList.Items[captionsList.SelectedIndex] = captionsList.SelectedItem;
                }
                else
                {
                    int n = 0;
                    while ((n < captionsList.Items.Count) && (((captionInfo)captionsList.Items[n]).start < curCaption.start))
                    {
                        n++;
                    }
                    captionsList.Items.Insert(n, curCaption);
                    //# This should only select if a caption at this time.
                    captionsList.SelectedIndex = n + 1;
                }

                curCaption        = new captionInfo(axWindowsMediaPlayer1.Ctlcontrols.currentPosition);
                curCaptionChanged = false;
                captionsList.Items.Add(curCaption);
                captionsList.SelectedIndex = captionsList.Items.Count - 1;
                editCurCaption();

                axWindowsMediaPlayer1.Ctlcontrols.play();
                changingCaptionIndex = false;
            }
            else
            {
                if (curCaption.length == 0)
                {
                    double len = axWindowsMediaPlayer1.Ctlcontrols.currentPosition - curCaption.start;
                    if (len > 0)
                    {
                        curCaption.length = len;
                        endEdt.Text       = curCaption.endTime();
                    }
                }
                axWindowsMediaPlayer1.Ctlcontrols.pause();
            }
        }
Пример #5
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (curCaption != null)
     {
         if (axWindowsMediaPlayer1.Ctlcontrols.currentPosition < curCaption.start)
         {
         }
         else if ((curCaption.length > 0) && (axWindowsMediaPlayer1.Ctlcontrols.currentPosition > curCaption.start + curCaption.length))
         {
             if (captionsList.SelectedIndex < captionsList.Items.Count - 1)
             {
                 captionsList.SelectedIndex++;
             }
             else
             {
                 curCaption = new captionInfo(axWindowsMediaPlayer1.Ctlcontrols.currentPosition);
                 captionsList.Items.Add(curCaption);
                 captionsList.SelectedIndex = captionsList.Items.Count - 1;
             }
         }
     }
 }
Пример #6
0
        private void openClosedCaptionsFile(string filename)
        {
            Regex readTimes = new Regex(@"\A\s*((?<sth>[0-9]+):)?(?<stm>[0-9]+):(?<sts>[0-9\.]+)\s*[->]+\s*((?<enh>[0-9]+):)?(?<enm>[0-9]+):(?<ens>[0-9\.]+)");
            Regex readVoice = new Regex(@"\A\s*<v\s+(?<voice>[^>]+)>\s*(?<caption>.*)");

            vttpath = filename;
            string[] vtt = File.ReadAllLines(vttpath);
            captionsList.Items.Clear();
            captionInfo cc        = null;
            bool        firstline = false;

            foreach (string ln in vtt)
            {
                Match tms = readTimes.Match(ln);
                if (tms.Success)
                {
                    if (cc != null)
                    {
                        captionsList.Items.Add(cc);
                    }
                    double start = 0;
                    if (tms.Groups["sth"].Success)
                    {
                        start += double.Parse(tms.Groups["sth"].Value) * 3600;
                    }
                    start += double.Parse(tms.Groups["stm"].Value) * 60;
                    start += double.Parse(tms.Groups["sts"].Value);
                    double end = 0;
                    if (tms.Groups["enh"].Success)
                    {
                        end += double.Parse(tms.Groups["enh"].Value) * 3600;
                    }
                    end      += double.Parse(tms.Groups["enm"].Value) * 60;
                    end      += double.Parse(tms.Groups["ens"].Value);
                    cc        = new captionInfo(start);
                    cc.length = end - start;
                    firstline = true;
                }
                else if (cc != null)
                {
                    if (firstline)
                    {
                        Match flm = readVoice.Match(ln);
                        if (flm.Success)
                        {
                            cc.voice   = flm.Groups["voice"].Value;
                            cc.caption = flm.Groups["caption"].Value;
                        }
                        else
                        {
                            cc.caption = ln;
                        }
                        firstline = false;
                    }
                    else
                    {
                        if (ln.Trim().Length > 0)
                        {
                            cc.caption += "\r\n" + ln;
                        }
                    }
                }
            }
            if (cc != null)
            {
                captionsList.Items.Add(cc);
            }
        }