Esempio n. 1
0
        private void AudioWaveFormDragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            string fileName = files[0];
            if (files.Length != 1)
            {
                MessageBox.Show(_language.DropOnlyOneFile);
                return;
            }

            string ext = Path.GetExtension(fileName).ToLower();
            if (ext != ".wav")
            {
                if (audioVisualizer.WavePeaks == null && (Utilities.GetMovieFileExtensions().Contains(ext) || ext == ".mp3"))
                {
                    _videoFileName = fileName;
                    AudioWaveForm_Click(null, null);
                    OpenVideo(_videoFileName);
                    return;
                }
                try
                {
                    var fi = new FileInfo(fileName);
                    if (fi.Length < 1024 * 500)
                    {
                        var lines = new List<string>();
                        foreach (string line in File.ReadAllLines(fileName))
                            lines.Add(line);
                        foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats)
                        {
                            if (format.IsMine(lines, fileName))
                            {
                                OpenSubtitle(fileName, null);
                                return;
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            if (string.IsNullOrEmpty(_videoFileName))
                buttonOpenVideo_Click(null, null);
            if (_videoFileName == null)
                return;

            if (ext != ".wav")
            {
                MessageBox.Show(string.Format(".Wav only!", fileName));
                return;
            }

            var addWaveForm = new AddWaveForm();
            string spectrogramFolder = GetSpectrogramFolder(_videoFileName);
            addWaveForm.InitializeViaWaveFile(fileName, spectrogramFolder);
            if (addWaveForm.ShowDialog() == DialogResult.OK)
            {
                string peakWaveFileName = GetPeakWaveFileName(_videoFileName);
                addWaveForm.WavePeak.WritePeakSamples(peakWaveFileName);
                var audioPeakWave = new WavePeakGenerator(peakWaveFileName);
                audioPeakWave.GenerateAllSamples();
                audioVisualizer.WavePeaks = audioPeakWave;
                timerWaveForm.Start();
            }
        }