private void Encode() { if (String.IsNullOrEmpty(InputFile) || !File.Exists(InputFile)) { MessageBox.Show("Please select a valid input file to convert"); return; } if (SelectedMediaType == null || SelectedMediaType.MediaType == null) { MessageBox.Show("Please select a valid output format"); return; } using (var reader = new SharpMediaFoundationReader(InputFile)) { string outputUrl = SelectSaveFile(SelectedOutputFormat.Name, SelectedOutputFormat.Extension); if (outputUrl == null) { return; } using (var encoder = new SharpMediaFoundationEncoder(SelectedMediaType.MediaType)) { encoder.Encode(outputUrl, reader); } } }
private void Play() { if (String.IsNullOrEmpty(InputPath)) { MessageBox.Show("Select a valid input file or URL first"); return; } if (lastPlayed != inputPath && reader != null) { reader.Dispose(); reader = null; } if (reader == null) { reader = new SharpMediaFoundationReader(inputPath); } if (wavePlayer == null) { CreatePlayer(); wavePlayer.Init(reader); } wavePlayer.Play(); OnPropertyChanged("IsPlaying"); OnPropertyChanged("IsStopped"); timer.Start(); }
private void Load() { if (reader != null) { reader.Dispose(); reader = null; } SelectInputFile(); }
private bool TryOpenInputFile(string file) { bool isValid = false; try { using (var reader = new SharpMediaFoundationReader(file)) { InputFormat = reader.WaveFormat.ToString(); inputWaveFormat = reader.WaveFormat; isValid = true; } } catch (Exception e) { MessageBox.Show(String.Format("Not a supported input file ({0})", e.Message)); } return(isValid); }
private bool TryOpenInputFile(Stream stream) { bool isValid = false; try { if (reader != null) { reader.Dispose(); } reader = new SharpMediaFoundationReader(stream); DefaultDecompressionFormat = reader.WaveFormat.ToString(); isValid = true; } catch (Exception e) { MessageBox.Show(String.Format("Not a supported input file ({0})", e.Message)); } return(isValid); }
private void RepositionTest() { if (String.IsNullOrEmpty(InputFile)) { MessageBox.Show("Select a file first"); return; } var saveFile = SelectSaveFile("reposition"); if (saveFile == null) { return; } // do the resample using (var reader = new SharpMediaFoundationReader(InputFile)) using (var resampler = new SharpMediaFoundationResampler(reader, CreateOutputFormat(reader.WaveFormat))) { CreateRepositionTestFile(saveFile, resampler, () => { // tell the reader to go back to the start (we're trusting it not to have leftovers) reader.Position = 0; // tell the resampler that we have repositioned and it should drain all its buffers resampler.Reposition(); }); } // use the following to test that just the reader is doing clean repositions: /* * using (var reader = new MediaFoundationReader(InputFile)) * { * CreateRepositionTestFile(saveFile, reader, () => * { * // tell the reader to go back to the start (we're trusting it not to have leftovers) * reader.Position = 0; * }); * }*/ MessageBox.Show("Resample complete"); }
private void Resample() { if (String.IsNullOrEmpty(InputFile)) { MessageBox.Show("Select a file first"); return; } var saveFile = SelectSaveFile("resampled"); if (saveFile == null) { return; } // do the resample using (var reader = new SharpMediaFoundationReader(InputFile)) using (var resampler = new SharpMediaFoundationResampler(reader, CreateOutputFormat(reader.WaveFormat))) { WaveFileWriter.CreateWaveFile(saveFile, resampler); } MessageBox.Show("Resample complete"); }