Пример #1
0
        private void AudioWaveForm_Click(object sender, EventArgs e)
        {
            if (audioVisualizer.WavePeaks == null)
            {
                if (string.IsNullOrEmpty(_videoFileName))
                {
                    buttonOpenVideo_Click(sender, e);
                    if (string.IsNullOrEmpty(_videoFileName))
                        return;
                }

                if (mediaPlayer != null)
                    mediaPlayer.Pause();
                var addWaveForm = new AddWaveForm();
                string peakWaveFileName = GetPeakWaveFileName(_videoFileName);
                string spectrogramFolder = GetSpectrogramFolder(_videoFileName);
                addWaveForm.Initialize(_videoFileName, spectrogramFolder, _videoAudioTrackNumber);
                if (addWaveForm.ShowDialog() == DialogResult.OK)
                {
                    addWaveForm.WavePeak.WritePeakSamples(peakWaveFileName);
                    var audioPeakWave = new WavePeakGenerator(peakWaveFileName);
                    audioPeakWave.GenerateAllSamples();
                    audioPeakWave.Close();
                    audioVisualizer.WavePeaks = audioPeakWave;
                    if (addWaveForm.SpectrogramBitmaps != null)
                        audioVisualizer.InitializeSpectrogram(addWaveForm.SpectrogramBitmaps, spectrogramFolder);
                    timerWaveForm.Start();
                }
            }
        }
Пример #2
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();
            }
        }