public void Stop() { if (waveOut != null) { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } if (baStream != null) { baStream.Dispose(); baStream = null; } if (wavStream != null) { wavStream.Dispose(); wavStream = null; } if (mf != null) { mf.Close(); mf.Dispose(); mf = null; } }
private void musicListPanelsButton_Click(object sender, EventArgs e) { audioPath = fileNames[Convert.ToInt32((sender as System.Windows.Forms.Button).Name)]; if (fileReader == null) { fileReader = new MediaFoundationReader(audioPath); } else { fileReader.Close(); fileReader.Dispose(); fileReader = new MediaFoundationReader(audioPath); } if (outputDevice == null) { outputDevice = new WaveOutEvent(); } else { outputDevice.Stop(); } musicTrackBar.Value = 0; musicIsPlaying = false; playButton.Text = ""; timerOfPlayback.Enabled = false; outputDevice.Init(fileReader); musicTrackBar.Maximum = fileReader.TotalTime.Minutes * 60 + fileReader.TotalTime.Seconds; maximumDuration.Text = fileReader.TotalTime.Minutes.ToString("00") + ":" + fileReader.TotalTime.Seconds.ToString("00"); playButton_Click(null, null); }
private static void WmaToWav(string wmaFile, string outputFile) { using (var reader = new MediaFoundationReader(wmaFile)) { WaveFileWriter.CreateWaveFile(outputFile, reader); reader.Close(); } }
private void saveLyricsToolStripMenuItem_Click(object sender, EventArgs e) { if (OFD.FileName != null) { foundationReader.Dispose(); foundationReader.Flush(); foundationReader.Close(); TagLib.File f = TagLib.File.Create(OFD.FileName); f.Tag.Lyrics = Lyrics_richtextbox.Text.Remove(0, f.Tag.Title.Length); f.Save(); foundationReader = new MediaFoundationReader(OFD.FileName); } }
public static void TestRheaStream(DiscordMessageEventArgs e) { DiscordVoiceClient vc = client.GetVoiceClient(); if (vc == null) { SendBotMessage("!@Not in a channel!", e.Channel); } try { int ms = 20;//buffer int channels = 1; int sampleRate = 48000; int blockSize = 48 * 2 * channels * ms; //sample rate * 2 * channels * milliseconds byte[] buffer = new byte[blockSize]; var outFormat = new WaveFormat(sampleRate, 16, channels); vc.SetSpeaking(true); using (var mp3Reader = new MediaFoundationReader("https://www.youtube.com/watch?v=2Vv-BfVoq4g")) { using (var resampler = new MediaFoundationResampler(mp3Reader, outFormat) { ResamplerQuality = 60 }) { int byteCount; while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0) { if (vc.Connected) { vc.SendVoice(buffer); } else { break; } } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Voice finished enqueuing"); Console.ForegroundColor = ConsoleColor.White; resampler.Dispose(); mp3Reader.Close(); } } } catch (Exception ex) { Log("Exception during voice: `" + ex.Message + "`\n\n```" + ex.StackTrace + "\n```", LogType.Console); } #endregion }
private void TestRheaStream() { DiscordVoiceClient vc = client.GetVoiceClient(); try { int ms = voiceMsBuffer; int channels = 1; int sampleRate = 48000; int blockSize = 48 * 2 * channels * ms; //sample rate * 2 * channels * milliseconds byte[] buffer = new byte[blockSize]; var outFormat = new WaveFormat(sampleRate, 16, channels); vc.SetSpeaking(true); using (var mp3Reader = new MediaFoundationReader("http://radiosidewinder.out.airtime.pro:8000/radiosidewinder_a")) { using (var resampler = new MediaFoundationResampler(mp3Reader, outFormat) { ResamplerQuality = 60 }) { int byteCount; while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0) { if (vc.Connected) { vc.SendVoice(buffer); } else { break; } } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Voice finished enqueuing"); Console.ForegroundColor = ConsoleColor.White; resampler.Dispose(); mp3Reader.Close(); } } } catch (Exception ex) { owner.SendMessage("Exception during voice: `" + ex.Message + "`\n\n```" + ex.StackTrace + "\n```"); } }
/// <summary> /// Manually stops the playing sound, or does nothing if the sound is not playing. /// </summary> internal void StopSound() { if (audioFileReader != null || waveOutDevice != null) { // if these vars still have valid contents, then the stop of sound is in process IsBeingStopped = true; } else { // these vars below are anyways set in the other if branch (after `return;` below) IsBeingStopped = false; justNormalPlaybackEnd = true; IsPlaying = false; return; } //ShouldBePlaying = false; justNormalPlaybackEnd = false; //if (volumeStream != null) // volumeStream.Dispose(); if (audioFileReader != null) { audioFileReader.Close(); audioFileReader.Dispose(); audioFileReader = null; } if (waveOutDevice != null) { waveOutDevice.Stop(); waveOutDevice.Dispose(); waveOutDevice = null; } justNormalPlaybackEnd = true; IsPlaying = false; }
private void SendVoice(string file, DiscordClient client) { DiscordVoiceClient vc = client.GetVoiceClient(); try { int ms = vc.VoiceConfig.FrameLengthMs; int channels = vc.VoiceConfig.Channels; int sampleRate = 48000; int blockSize = 48 * 2 * channels * ms; //sample rate * 2 * channels * milliseconds byte[] buffer = new byte[blockSize]; var outFormat = new WaveFormat(sampleRate, 16, channels); vc.SetSpeaking(true); if (file.EndsWith(".wav")) { using (var waveReader = new WaveFileReader(file)) { int byteCount; while ((byteCount = waveReader.Read(buffer, 0, blockSize)) > 0) { if (vc.Connected) { vc.SendVoice(buffer); } else { break; } } } } else if (file.EndsWith(".mp3")) { using (var mp3Reader = new MediaFoundationReader(file)) { using (var resampler = new MediaFoundationResampler(mp3Reader, outFormat) { ResamplerQuality = 60 }) { //resampler.ResamplerQuality = 60; int byteCount; while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0) { if (vc.Connected) { vc.SendVoice(buffer); } else { break; } } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Voice finished enqueuing"); Console.ForegroundColor = ConsoleColor.White; resampler.Dispose(); mp3Reader.Close(); } } } } catch (Exception ex) { try { MainEntry.owner.SendMessage("Exception during voice: `" + ex.Message + "`\n\n```" + ex.StackTrace + "\n```"); } catch { } } }
static void Main(string[] args) { if (!VTConsole.IsSupported) { return; } VTConsole.Enable(); Console.OutputEncoding = Encoding.UTF8; Console.WriteLine("https://github.com/009342/ConsoleVideoPlayer"); if (args.Length == 0) { return; } //video : music bool isSound = true; VideoFileReader vfr = new VideoFileReader(); WaveOut waveOut = new WaveOut(); if (args.Length == 2) { size = int.Parse(args[1]); } audioFileReader = new AudioFileReader(args[0]); MediaFoundationReader video = null; try { Console.WriteLine("오디오 정보"); Console.WriteLine("인코딩 : " + audioFileReader.WaveFormat.ToString()); Console.WriteLine("샘플레이트 : " + audioFileReader.WaveFormat.SampleRate); Console.WriteLine("채널 : " + audioFileReader.WaveFormat.Channels); Console.WriteLine("길이 :" + audioFileReader.Length); } catch (Exception e) { isSound = false; Console.WriteLine("소리를 재생할 수 없습니다."); Console.WriteLine("오류 : " + e.ToString()); } vfr.Open(args[0]); double fps = (double)vfr.FrameRateNum / (double)vfr.FrameRateDen; fps = (fps > 59) ? 30 : fps; Console.WriteLine("비디오 정보"); Console.WriteLine("코덱 정보 : " + vfr.CodecName); Console.WriteLine("초당 프레임 : " + fps.ToString()); Console.WriteLine("총 프레임 : " + vfr.FrameCount); Console.WriteLine("너비 : " + vfr.Width); Console.WriteLine("높이 : " + vfr.Height); int Count = 5; while (Count-- > 0) { Console.WriteLine(Count.ToString()); Thread.Sleep(1000); } Console.Clear(); int c_width = 189; int c_height = 50; Console.SetWindowSize( Math.Min(c_width, Console.LargestWindowWidth), Console.LargestWindowHeight); int v_width = vfr.Width; int v_height = vfr.Height; int b_width = v_width / c_width; int b_height = v_height / c_height; if (isSound) { waveOut.Init(audioFileReader); } if (isSound) { waveOut.Play(); } Bitmap bm = new Bitmap(vfr.Width, vfr.Height); Random random = new Random(); Thread videoDecoderThread = new Thread(() => { VideoDecoderThread(vfr, fps); }); Thread frameDisposerThread = new Thread(() => { FrameDisposerThread(vfr); }); videoDecoderThread.Start(); frameDisposerThread.Start(); bool EOF = false; int tempIndex = 0; for (; ;) { while (Frames.Count < (int)((audioFileReader.CurrentTime.TotalMilliseconds / 1000) * fps) + healthy) { if (vfr.CurrentFrame + 1 == vfr.FrameCount) { EOF = true; break; } Thread.Sleep(10); Console.Title = "패스 : " + vfr.CurrentFrame.ToString() + "/" + ((audioFileReader.CurrentTime.TotalMilliseconds / 1000) * fps).ToString(); } if (EOF) { break; } tempIndex = (int)((audioFileReader.CurrentTime.TotalMilliseconds / 1000) * fps); bm = Frames[tempIndex]; if (bm == null) { break; } Console.Title = "현재 프레임 : " + vfr.CurrentFrame.ToString() + " 제거된 프레임 : " + disposedFrame + " 시간 : " + ((audioFileReader.CurrentTime.TotalMilliseconds / 1000)).ToString() + "초당 프레임 : " + fps.ToString(); Console.SetCursorPosition(0, 0); //Console.Title = "콘솔 출력중..."; ConsoleWriteImage2(bm); //Console.Title = "콘솔 출력 완료..."; SetCurrentFrame(tempIndex); } vfr.Close(); if (isSound) { video.Close(); } videoDecoderThread.Abort(); frameDisposerThread.Abort(); }
public byte[] Decode(string audioType, byte[] input) { byte[] output = null; _calls++; lock (_decoderLock) { string fileType = ""; switch (audioType) { case "audio/mpg": case "audio/mpeg": fileType = "mp3"; break; case "audio/aac": case "audio/aacp": fileType = "aac"; break; } try { string _inFile = PathUtils.GetTempFilePath(string.Format("opm-dec-in-{1}.{0}", fileType, _calls % 10)); string _outFile = PathUtils.GetTempFilePath(string.Format("opm-dec-out.wav")); DeleteFile(_outFile); DeleteFile(_inFile); IO.File.WriteAllBytes(_inFile, input); WaveFormat wf = new WaveFormat(WaveFormatEx.Cdda.nSamplesPerSec, 2); using (MediaFoundationReader mfr = new MediaFoundationReader(_inFile)) using (ResamplerDmoStream res = new ResamplerDmoStream(mfr, wf)) using (WaveFileWriter wav = new WaveFileWriter(_outFile, wf)) { res.CopyTo(wav); wav.Close(); res.Close(); mfr.Close(); } if (IO.File.Exists(_outFile)) { byte[] outWav = IO.File.ReadAllBytes(_outFile); if (outWav.Length > 44) { output = new byte[outWav.Length]; Array.Copy(outWav, 44, output, 0, outWav.Length - 44); } } } catch (Exception ex) { Logger.LogException(ex); } } return(output); }