private void StopAudio() { if (_audio != null) { if (_waveReader != null) { _waveReader.Dispose(); _waveReader = null; } if (_mp3Reader != null) { _mp3Reader.Dispose(); _mp3Reader = null; } try { _audio.PlaybackStopped -= PreviewAudio_PlaybackStopped; _audio.Stop(); _audio.Dispose(); } catch (Exception e) { Logger.Warn($"Error stopping audio: {e.Message}"); } _audio = null; NotifyPropertyChanged(nameof(IsPlayingAudio)); } }
private void readDataAndDraw() { short[] data = null; NAudio.Wave.WaveStream reader = null; if (t.Format.Equals("MP3")) { reader = new NAudio.Wave.Mp3FileReader(t.Path); } else if (t.Format.Equals("WAV")) { reader = new NAudio.Wave.WaveFileReader(t.Path); } if (reader != null) { byte[] buffer = new byte[reader.Length]; int read = reader.Read(buffer, 0, buffer.Length); data = new short[read / sizeof(short)]; Buffer.BlockCopy(buffer, 0, data, 0, read); } List <short> chan1 = new List <short>(); List <short> chan2 = new List <short>(); for (int i = 0; i < data.Length - 1; i += 2) { chan1.Add(data[i]); chan2.Add(data[i + 1]); } plot(chan1.ToArray()); }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "MP3 File (*.mp3)|*.mp3;"; if (open.ShowDialog() != DialogResult.OK) { return; } SaveFileDialog save = new SaveFileDialog(); save.Filter = "WAV File (*.wav)|*.wav;"; if (save.ShowDialog() != DialogResult.OK) { return; } using (NAudio.Wave.Mp3FileReader mp3 = new NAudio.Wave.Mp3FileReader(open.FileName)) { using (NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(mp3)) { NAudio.Wave.WaveFileWriter.CreateWaveFile(save.FileName, pcm); } } }
private double GetLengthToDouble(string Path) { NAudio.Wave.Mp3FileReader mp3FileReader; NAudio.Wave.WaveFileReader waveFileReader; TimeSpan timeSpan = new TimeSpan(); try { if (System.IO.Path.GetExtension(Path) == ".mp3") { mp3FileReader = new NAudio.Wave.Mp3FileReader(Path); timeSpan = mp3FileReader.TotalTime; mp3FileReader.Dispose(); } if (System.IO.Path.GetExtension(Path) == ".wav") { waveFileReader = new NAudio.Wave.WaveFileReader(Path); waveFileReader.Dispose(); timeSpan = waveFileReader.TotalTime; } return(timeSpan.TotalSeconds); } catch (Exception) { return(0.0d); } }
void NextSongFunc() { //if (getCurrrentTime_th != null && (getCurrrentTime_th.ThreadState & ThreadState.Running )== ThreadState.Running) //{ // getCurrrentTime_th.Suspend(); //} isCausedByFunc = true; if (songList != null && songList.Length != 0) { Play = "Pause"; PlayingIndex = (PlayingIndex + songList.Length + 1) % songList.Length; wo.Stop(); wo.Dispose(); mp3FileReader = new NAudio.Wave.Mp3FileReader(songList[PlayingIndex].FullName); PlayingTotalTime = mp3FileReader.TotalTime.ToString().Substring(0, 8); string[] temp = songList[PlayingIndex].Name.Split('-'); SingerName = temp[0]; SongName = temp[1]; wo.Init(mp3FileReader); wo.Play(); //Thread.Sleep(500); //if (getCurrrentTime_th != null && (getCurrrentTime_th.ThreadState & ThreadState.Suspended) == ThreadState.Suspended) //{ // getCurrrentTime_th.Resume(); //} if ((getCurrrentTime_th.ThreadState & ThreadState.Unstarted) == ThreadState.Unstarted) { getCurrrentTime_th.Start(); } IsPlayed = true; IsPlaying = true; } }
public static void ConvertMp3ToWav(string _inPath_, string _outPath_) { using (NAudio.Wave.Mp3FileReader mp3 = new NAudio.Wave.Mp3FileReader(_inPath_)) { using (NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(mp3)) { NAudio.Wave.WaveFileWriter.CreateWaveFile(_outPath_, pcm); } } }
public static void ConvertMp3ToWav(System.IO.Stream sourceStream, System.IO.Stream destinationStream) { using (var mp3 = new NAudio.Wave.Mp3FileReader(sourceStream)) { using (NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(mp3)) { NAudio.Wave.WaveFileWriter.WriteWavFileToStream(destinationStream, pcm); } } }
private static async void SendMP3AudioFile(string filePath) { Channel channel = _audioClient.Channel; filePath = ConvertToMp3(filePath); int channelCount = _client.GetService <AudioService>().Config.Channels; NAudio.Wave.WaveFormat OutFormat = new NAudio.Wave.WaveFormat(48000, 16, channelCount); using (NAudio.Wave.Mp3FileReader MP3Reader = new NAudio.Wave.Mp3FileReader(filePath)) { using (NAudio.Wave.MediaFoundationResampler resampler = new NAudio.Wave.MediaFoundationResampler(MP3Reader, OutFormat)) { resampler.ResamplerQuality = 60; int blockSize = OutFormat.AverageBytesPerSecond / 50; byte[] buffer = new byte[blockSize]; int byteCount; while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0) { if (byteCount < blockSize) { for (int i = byteCount; i < blockSize; ++i) { buffer[i] = 0; } } if (_audioClient.State == ConnectionState.Disconnecting || _audioClient.State == ConnectionState.Disconnected) { System.Threading.Thread.Sleep(1000); } try { _audioClient.Send(buffer, 0, blockSize); } #pragma warning disable CS0168 // Variable is declared but never used, supressed error because it must be declared to be caught catch (OperationCanceledException e) #pragma warning restore CS0168 { //if (!(_audioClient.State == ConnectionState.Disconnecting || _audioClient.State == ConnectionState.Disconnected)) //{ _audioClient = await JoinAudioChannel(channel); System.Threading.Thread.Sleep(1000); _audioClient.Send(buffer, 0, blockSize); //} } } //await _audioClient.Disconnect(); } } _nextSong = true; }
/// <summary> /// MP3 转 WAV 不支持网络 URI 路径 /// </summary> /// <param name="mp3filePath"></param> /// <param name="wavfilePath"></param> public static void Mp3ToWav(string mp3filePath, string wavfilePath) { CreateNonExistsDirectory(wavfilePath); using (NAudio.Wave.Mp3FileReader reader = new NAudio.Wave.Mp3FileReader(mp3filePath)) { using (NAudio.Wave.WaveStream pcmStream = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(reader)) { NAudio.Wave.WaveFileWriter.CreateWaveFile(wavfilePath, pcmStream); } } }
private int GetLength(string Path) { NAudio.Wave.Mp3FileReader mp3FileReader = new NAudio.Wave.Mp3FileReader(Path); TimeSpan timeSpan = mp3FileReader.TotalTime; int Length = (timeSpan.Days * 86400) + (timeSpan.Hours * 3600) + (timeSpan.Minutes * 60) + timeSpan.Seconds; if (Length == 0 && timeSpan.Milliseconds > 500) { Length = 1; } mp3FileReader.Dispose(); return(Length); }
private void btnPlay_Click(object sender, EventArgs e) { if(lbArtists.SelectedIndex == -1 || lbAlbums.SelectedIndex == -1 || lbSongs.SelectedIndex == -1) { MessageBox.Show("Noting selected"); return; } byte[] data = _client.GetSongData(_musicCollection.Artists[lbArtists.SelectedIndex].Albums[lbAlbums.SelectedIndex].Songs[lbSongs.SelectedIndex].ID); MemoryStream ms = new MemoryStream(data); NAudio.Wave.Mp3FileReader reader = new NAudio.Wave.Mp3FileReader(ms); NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut(); waveOut.Init(reader); waveOut.Play(); }
public static float[] ReadMp3(string mp3FilePath, int?sampleLimit = null) { string actualPath = FindFile(mp3FilePath); var reader = new NAudio.Wave.Mp3FileReader(actualPath); int bytesToRead = (int)reader.Length; if (sampleLimit != null) { bytesToRead = Math.Min(bytesToRead, (int)sampleLimit * 2); } byte[] bytes = new byte[bytesToRead]; reader.Read(bytes, 0, bytesToRead); float[] pcm = FloatsFromBytesINT16(bytes); return(pcm); }
private string GetLength(string Path) { NAudio.Wave.Mp3FileReader mp3FileReader; NAudio.Wave.WaveFileReader waveFileReader; TimeSpan timeSpan = new TimeSpan(); try { if (System.IO.Path.GetExtension(Path) == ".mp3") { mp3FileReader = new NAudio.Wave.Mp3FileReader(Path); timeSpan = mp3FileReader.TotalTime; mp3FileReader.Dispose(); } if (System.IO.Path.GetExtension(Path) == ".wav") { waveFileReader = new NAudio.Wave.WaveFileReader(Path); waveFileReader.Dispose(); timeSpan = waveFileReader.TotalTime; } int dd = timeSpan.Days; int hh = timeSpan.Hours; int mm = timeSpan.Minutes; int ss = timeSpan.Seconds; string t = ""; if (dd > 0) { t += $"{dd}D:"; } if (hh > 0) { t += $"{hh}H:"; } if (mm > 0) { t += $"{mm}M:"; } if (ss > 0) { t += $"{ss}s"; } return(t); } catch (Exception) { return(""); } }
/// <summary> /// Load a sound for the animation from a byte array. /// </summary> /// <remarks>If this function fails, no sound will be played for this pet.</remarks> public void Load(byte[] buff) { try { MemoryStream ms = new MemoryStream(buff); AudioReader = new NAudio.Wave.Mp3FileReader(ms); Audio = new NAudio.Wave.WaveOut(); Audio.Init(AudioReader); Audio.PlaybackStopped += Audio_PlaybackStopped; } catch (Exception e) { Program.AddLog("Unable to load MP3: " + e.Message, "Play pet", Program.LOG_TYPE.ERROR); } }
static private double GetDuration(string nameFile) { if (File.Exists(nameFile + ".wav")) { NAudio.Wave.WaveFileReader wf = new NAudio.Wave.WaveFileReader(nameFile + ".wav"); return(wf.TotalTime.TotalSeconds); } if (File.Exists(nameFile + ".mp3")) { NAudio.Wave.Mp3FileReader mp3f = new NAudio.Wave.Mp3FileReader(nameFile + ".mp3"); return(mp3f.TotalTime.TotalSeconds); } return(0); }
public static void ProcessFile(string fileName) { try { string fileExt = System.IO.Path.GetExtension(fileName.ToLower()); if (fileExt.Contains("mp3")) { using (NAudio.Wave.Mp3FileReader rdr = new NAudio.Wave.Mp3FileReader(fileName)) { //var newFormat = new NAudio.Wave.WaveFormat(48000, 16, 1); var newFormat = new NAudio.Wave.WaveFormat(16000, 16, 1); using (var conversionStream = new NAudio.Wave.WaveFormatConversionStream(newFormat, rdr)) { if (System.IO.File.Exists("mdc1200tmp.wav")) { System.IO.File.Delete("mdc1200tmp.wav"); } NAudio.Wave.WaveFileWriter.CreateWaveFile("mdc1200tmp.wav", conversionStream); } } } else { using (NAudio.Wave.WaveFileReader rdr = new NAudio.Wave.WaveFileReader(fileName)) { var newFormat = new NAudio.Wave.WaveFormat(16000, 16, 1); using (var conversionStream = new NAudio.Wave.WaveFormatConversionStream(newFormat, rdr)) { if (System.IO.File.Exists("mdc1200tmp.wav")) { System.IO.File.Delete("mdc1200tmp.wav"); } NAudio.Wave.WaveFileWriter.CreateWaveFile("mdc1200tmp.wav", conversionStream); } } } using (NAudio.Wave.AudioFileReader rdr = new NAudio.Wave.AudioFileReader("mdc1200tmp.wav")) { ProcessProvider(rdr, fileName); } } catch (Exception ex) { Console.WriteLine("Process File Exception: {0}", ex.Message); } }
public void Play(string track) { if (o != null) { o.Dispose(); mp3.Dispose(); memstream.Dispose(); } var bytes = ShiftOS.Objects.ShiftFS.Utils.ReadAllBytes(track); memstream = new System.IO.MemoryStream(bytes); mp3 = new NAudio.Wave.Mp3FileReader(memstream); o = new NAudio.Wave.WaveOut(); o.Init(mp3); o.Play(); pgplaytime.Value = 0; pgplaytime.Maximum = (int)mp3.Length; new Thread(() => { while (o.PlaybackState == NAudio.Wave.PlaybackState.Playing || o.PlaybackState == NAudio.Wave.PlaybackState.Paused) { long time = mp3.Position; this.Invoke(new Action(() => { pgplaytime.Value = (int)time; })); Thread.Sleep(50); } if (o.PlaybackState == NAudio.Wave.PlaybackState.Stopped) { this.Invoke(new Action(() => { if (lbtracks.SelectedIndex < lbtracks.Items.Count - 1) { lbtracks.SelectedIndex++; } else if (loopToolStripMenuItem.Checked == true) { lbtracks.SelectedIndex = 0; } })); } }).Start(); }
/// <summary> /// Load a sound for the animation from a byte array. /// </summary> /// <remarks>If this function fails, no sound will be played for this pet.</remarks> public void Load(byte[] buff) { try { MemoryStream ms = new MemoryStream(buff); AudioReader = new NAudio.Wave.Mp3FileReader(ms); Audio = new NAudio.Wave.WaveOut(); Audio.Init(AudioReader); Audio.PlaybackStopped += Audio_PlaybackStopped; } catch (Exception e) { // Failed to create a wave, reset volume Properties.Settings.Default.Volume = 0; Program.Mainthread.ErrorMessages.AudioErrorMessage = e.Message; } }
public NAudioSource(string file) : this() { LoadMetadata(file); var reader = new NAudio.Wave.Mp3FileReader(file); var cc = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(reader); inputstream = new NAudio.Wave.BlockAlignReductionStream(cc); Length = inputstream.Length; BitsPerSample = inputstream.WaveFormat.BitsPerSample; Channels = inputstream.WaveFormat.Channels; SampleFrequency = inputstream.WaveFormat.SampleRate; WaveFormat = inputstream.WaveFormat; if (BitsPerSample != 16 || Channels != 2) throw new NotImplementedException(); Name = System.IO.Path.GetFileNameWithoutExtension(file); // FillBuffer(); //ThreadPool.QueueUserWorkItem(PopulateBuffer); }
public static void ProcessFile(string fileName) { try { string fileExt = System.IO.Path.GetExtension(fileName.ToLower()); if (fileExt.Contains("mp3")) { using (NAudio.Wave.Mp3FileReader rdr = new NAudio.Wave.Mp3FileReader(fileName)) { //var newFormat = new NAudio.Wave.WaveFormat(48000, 16, 1); var newFormat = new NAudio.Wave.WaveFormat(16000, 16, 1); using (var conversionStream = new NAudio.Wave.WaveFormatConversionStream(newFormat, rdr)) { if (System.IO.File.Exists("mdc1200tmp.wav")) System.IO.File.Delete("mdc1200tmp.wav"); NAudio.Wave.WaveFileWriter.CreateWaveFile("mdc1200tmp.wav", conversionStream); } } } else { using (NAudio.Wave.WaveFileReader rdr = new NAudio.Wave.WaveFileReader(fileName)) { var newFormat = new NAudio.Wave.WaveFormat(16000, 16, 1); using (var conversionStream = new NAudio.Wave.WaveFormatConversionStream(newFormat, rdr)) { if (System.IO.File.Exists("mdc1200tmp.wav")) System.IO.File.Delete("mdc1200tmp.wav"); NAudio.Wave.WaveFileWriter.CreateWaveFile("mdc1200tmp.wav", conversionStream); } } } using (NAudio.Wave.AudioFileReader rdr = new NAudio.Wave.AudioFileReader("mdc1200tmp.wav")) { ProcessProvider(rdr, fileName); } } catch (Exception ex) { Console.WriteLine("Process File Exception: {0}", ex.Message); } }
void PlaySongFunc() { if (!IsPlaying) { Play = "Pause"; IsPlaying = !IsPlaying; if (songList != null && songList.Length != 0) { if (!IsPlayed) { string[] temp = songList[PlayingIndex].Name.Split('-'); SingerName = temp[0]; SongName = temp[1]; mp3FileReader = new NAudio.Wave.Mp3FileReader(songList[PlayingIndex].FullName); PlayingTotalTime = mp3FileReader.TotalTime.ToString().Substring(0, 8); wo.Init(mp3FileReader); getCurrrentTime_th.Start(); wo.Play(); IsPlayed = true; } else { wo.Resume(); if (getCurrrentTime_th != null && (getCurrrentTime_th.ThreadState & ThreadState.Suspended) == ThreadState.Suspended) { getCurrrentTime_th.Resume(); } } } } else { Play = "Play"; IsPlaying = !IsPlaying; if (getCurrrentTime_th != null && (getCurrrentTime_th.ThreadState & ThreadState.Running) == ThreadState.Running) { getCurrrentTime_th.Suspend(); } wo.Pause(); } }
static void Main(string[] args) { if (args.Count() == 0) { Console.WriteLine("Basic text to speach converter"); Console.WriteLine("Expecting text in the command line parameter"); Environment.Exit(0); } Console.WriteLine("Creating Amazon Polly client"); Amazon.Polly.AmazonPollyClient cl = new Amazon.Polly.AmazonPollyClient(RegionEndpoint.USWest2); Amazon.Polly.Model.SynthesizeSpeechRequest req = new Amazon.Polly.Model.SynthesizeSpeechRequest(); req.Text = String.Join(" ", args); req.VoiceId = Amazon.Polly.VoiceId.Salli; req.OutputFormat = Amazon.Polly.OutputFormat.Mp3; req.SampleRate = "8000"; req.TextType = Amazon.Polly.TextType.Text; Console.WriteLine("Sending Amazon Polly request: " + req.Text); Amazon.Polly.Model.SynthesizeSpeechResponse resp = cl.SynthesizeSpeech(req); MemoryStream local_stream = new MemoryStream(); resp.AudioStream.CopyTo(local_stream); local_stream.Position = 0; Console.WriteLine("Got mp3 stream, lenght: " + local_stream.Length.ToString()); NAudio.Wave.Mp3FileReader reader = new NAudio.Wave.Mp3FileReader(local_stream); NAudio.Wave.WaveStream wave_stream = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(reader); NAudio.Wave.BlockAlignReductionStream ba_stream = new NAudio.Wave.BlockAlignReductionStream(wave_stream); NAudio.Wave.WaveOut wout = new NAudio.Wave.WaveOut(); Console.Write("Playing stream..."); wout.Init(ba_stream); wout.Play(); while (wout.PlaybackState == NAudio.Wave.PlaybackState.Playing) { Thread.Sleep(100); } Console.WriteLine("..Done"); }
private short[] readDataFromFile() { short[] data = null; NAudio.Wave.WaveStream reader = null; if (t.Format.Equals("MP3")) { reader = new NAudio.Wave.Mp3FileReader(t.Path); } else if (t.Format.Equals("WAV")) { reader = new NAudio.Wave.WaveFileReader(t.Path); } if (reader != null) { byte[] buffer = new byte[reader.Length]; int read = reader.Read(buffer, 0, buffer.Length); data = new short[read / sizeof(short)]; Buffer.BlockCopy(buffer, 0, data, 0, read); } return(data); }
private void Form1_Shown(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Audio Files (*.wav, *.mp3)|*.wav; *.mp3"; open.Multiselect = true; open.Title = "Choose songs"; DialogResult dr = open.ShowDialog(); if (dr == DialogResult.OK) { WMPLib.IWMPPlaylist playlist = mediaPlayer.playlistCollection.newPlaylist("Current Playlist"); foreach (string file in open.FileNames) { WMPLib.IWMPMedia media = mediaPlayer.newMedia(file); playlist.appendItem(media); if (file.EndsWith(".mp3")) { using (NAudio.Wave.Mp3FileReader mp3 = new NAudio.Wave.Mp3FileReader(file)) { using (NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(mp3)) { int startIndex = file.LastIndexOf('\\'); string tempFile = appDataFolder + file.Substring(startIndex) + ".temp.wav"; Directory.CreateDirectory(tempFile.Substring(0, tempFile.LastIndexOf('\\'))); NAudio.Wave.WaveFileWriter.CreateWaveFile(tempFile, mp3); readPlaylist.Add(tempFile); } } } else { readPlaylist.Add(file); } } mediaPlayer.currentPlaylist = playlist; mediaPlayer.Ctlcontrols.play(); } }
private void btnOpen_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Sound Files (*.mp3;*.wav)|*.mp3;*.wav;"; open.ShowDialog(); DisposeWave(); //wave = new NAudio.Wave.WaveFileReader(open.FileName); if (open.FileName.EndsWith(".mp3")) { NAudio.Wave.WaveStream pcm = new NAudio.Wave.Mp3FileReader(open.FileName); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else if (open.FileName.EndsWith(".wav")) { NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } output = new NAudio.Wave.WaveOutEvent(); output.Init(new NAudio.Wave.WaveChannel32(stream)); output.Play(); StopWatch(); if (stopWatch.IsRunning) { stopWatch.Stop(); } else { stopWatch.Start(); } btnPausePlay.IsEnabled = true; }catch (ArgumentException) { System.Windows.MessageBox.Show("Choose a real file"); } }
void PreviousSongFunc() { isCausedByFunc = true; songList = playEntity.Traversal(); if (songList != null && songList.Length != 0) { Play = "Pause"; PlayingIndex = (PlayingIndex + songList.Length - 1) % songList.Length; wo.Dispose(); mp3FileReader = new NAudio.Wave.Mp3FileReader(songList[PlayingIndex].FullName); PlayingTotalTime = mp3FileReader.TotalTime.ToString().Substring(0, 8); string[] temp = songList[PlayingIndex].Name.Split('-'); SingerName = temp[0]; SongName = temp[1]; wo.Init(mp3FileReader); wo.Play(); if ((getCurrrentTime_th.ThreadState & ThreadState.Unstarted) == ThreadState.Unstarted) { getCurrrentTime_th.Start(); } IsPlayed = true; IsPlaying = true; } }
public static void Brute() { TerminalBackend.PrefixEnabled = false; bool cracked = false; var brute = Properties.Resources.brute; var str = new System.IO.MemoryStream(brute); var reader = new NAudio.Wave.Mp3FileReader(str); var _out = new NAudio.Wave.WaveOut(); _out.Init(reader); _out.PlaybackStopped += (o, a) => { if (cracked == false) { cracked = true; TerminalCommands.Clear(); ConsoleEx.Bold = true; ConsoleEx.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" - access denied - "); ConsoleEx.ForegroundColor = ConsoleColor.Gray; ConsoleEx.Bold = false; ConsoleEx.Italic = true; Console.WriteLine("password could not be cracked before connection termination."); } TerminalBackend.PrefixEnabled = true; TerminalBackend.PrintPrompt(); _out.Dispose(); reader.Dispose(); str.Dispose(); }; _out.Play(); var t = new Thread(() => { Console.WriteLine("brute - version 1.0"); Console.WriteLine("Copyright (c) 2018 hacker101. All rights reserved."); Console.WriteLine(); Thread.Sleep(4000); Console.WriteLine("Scanning outbound connections..."); if (string.IsNullOrWhiteSpace(Applications.FileSkimmer.OpenConnection.SystemName)) { Thread.Sleep(2000); Console.WriteLine(" - no outbound connections to scan, aborting - "); _out.Stop(); _out.Dispose(); reader.Dispose(); str.Dispose(); } else { Thread.Sleep(2000); var con = Applications.FileSkimmer.OpenConnection; Console.WriteLine($@"{con.SystemName} ------------------ Active connection: ftp, rts System name: {con.SystemName} Users: {con.Users.Count}"); Thread.Sleep(500); var user = con.Users.FirstOrDefault(x => x.Permissions == Objects.UserPermissions.Root); if (user == null) { Console.WriteLine(" - no users found with root access - this is a shiftos bug - "); } else { Console.WriteLine(" - starting bruteforce attack on user: "******" - "); char[] pass = new char[user.Password.Length]; for (int i = 0; i < pass.Length; i++) { if (cracked == true) { break; } for (char c = (char)0; c < (char)255; c++) { if (!char.IsLetterOrDigit(c)) { continue; } pass[i] = c; if (pass[i] == user.Password[i]) { break; } Console.WriteLine(new string(pass)); } } if (cracked == false) { cracked = true; TerminalCommands.Clear(); Console.WriteLine(" - credentials cracked. -"); Console.WriteLine($@"sysname: {con.SystemName} user: {user.Username} password: {user.Password}"); } } } }); t.Start(); }
internal static void StartAmbientLoop() { var athread = new Thread(() => { MemoryStream str = null; NAudio.Wave.Mp3FileReader mp3 = null; NAudio.Wave.WaveOut o = null; bool shuttingDown = false; Engine.AppearanceManager.OnExit += () => { shuttingDown = true; o?.Stop(); o?.Dispose(); mp3?.Close(); mp3?.Dispose(); str?.Close(); str?.Dispose(); }; while (shuttingDown == false) { if (Engine.SaveSystem.CurrentSave != null) { if (Engine.SaveSystem.CurrentSave.MusicEnabled) { str = new MemoryStream(GetRandomSong()); mp3 = new NAudio.Wave.Mp3FileReader(str); o = new NAudio.Wave.WaveOut(); o.Init(mp3); bool c = false; o.Play(); o.PlaybackStopped += (s, a) => { c = true; }; while (!c) { if (Engine.SaveSystem.CurrentSave.MusicEnabled) { try { o.Volume = (float)Engine.SaveSystem.CurrentSave.MusicVolume / 100; } catch { } } else { o.Stop(); c = true; } Thread.Sleep(10); } } else { Thread.Sleep(10); } } else { Thread.Sleep(10); } } }); athread.IsBackground = true; athread.Start(); }
private void PlaySound(SaveFile.Sound Item) { foreach (System.Windows.Forms.TreeNode DeviceNode in this.treeView1.Nodes) { if (DeviceNode.Checked && DeviceNode.Tag != null && ((SaveFile.Device)DeviceNode.Tag).CurrentDevice != null) { try { NAudio.Wave.WaveStream Stream; if (Item.SndFormat == SoundFormat.OGG) { Stream = new NAudio.Vorbis.VorbisWaveReader(Item.FilePath); } else if (Item.SndFormat == SoundFormat.WAV) { Stream = new NAudio.Wave.WaveFileReader(Item.FilePath); } else if (Item.SndFormat == SoundFormat.MP3) { Stream = new NAudio.Wave.Mp3FileReader(Item.FilePath); } else if (Item.SndFormat == SoundFormat.AIFF) { Stream = new NAudio.Wave.AiffFileReader(Item.FilePath); } else { throw new System.NotSupportedException(); } if (this.UserData.LoopEnabled) { Stream = new LoopStream(Stream); } NAudio.Wave.WasapiOut PlayAudio = new NAudio.Wave.WasapiOut((NAudio.CoreAudioApi.MMDevice)((SaveFile.Device)DeviceNode.Tag).CurrentDevice, NAudio.CoreAudioApi.AudioClientShareMode.Shared, true, 100); this.CurrentlyPlaying.Add(PlayAudio); { PlayAudio.Init(Stream); PlayAudio.Play(); } PlayAudio.PlaybackStopped += this.WaveOut_PlaybackStopped; } catch (System.FormatException Ex) { LucasStuff.Message.Show(Ex.Message, "An error occured while playing", LucasStuff.Message.Buttons.OK, LucasStuff.Message.Icon.Error); return; } catch (System.IO.InvalidDataException Ex) { LucasStuff.Message.Show(Ex.Message, "An error occured while playing", LucasStuff.Message.Buttons.OK, LucasStuff.Message.Icon.Error); return; } catch (System.IO.FileNotFoundException Ex) { System.Windows.Forms.DialogResult Result = LucasStuff.Message.Show(Ex.Message + "\n\nShould this file be removed from your audio listing?", "An error occured while playing", LucasStuff.Message.Buttons.YesNo, LucasStuff.Message.Icon.Error); if (Result == System.Windows.Forms.DialogResult.Yes) { //this.DeleteSounds(); // HACK: fix this before PC 1.0 Update #1 } return; } } } }
internal void PlayPreviewAudio() { if (_audio == null) { try { if (_audioFileName.EndsWith(".ogg", StringComparison.InvariantCultureIgnoreCase)) { if (!string.IsNullOrWhiteSpace(_audioPath)) { _audio = new NAudio.Wave.WaveOut(); _waveReader = new NAudio.Vorbis.VorbisWaveReader(_audioPath); _audio.Init(_waveReader); } else if (_audioFile != null) { _audio = new NAudio.Wave.WaveOut(); _waveReader = new NAudio.Vorbis.VorbisWaveReader(_audioFile); _audio.Init(_waveReader); } } else if (_audioFileName.EndsWith(".mp3", StringComparison.InvariantCultureIgnoreCase)) { if (!string.IsNullOrWhiteSpace(_audioPath)) { _audio = new NAudio.Wave.WaveOut(); _mp3Reader = new NAudio.Wave.Mp3FileReader(_audioPath); _audio.Init(_mp3Reader); } else if (_audioFile != null) { _audio = new NAudio.Wave.WaveOut(); _mp3Reader = new NAudio.Wave.Mp3FileReader(_audioFile); _audio.Init(_mp3Reader); } } else { Logger.Warn($"Unsupported audio file: {_audioFileName}"); return; } if (_waveReader != null || _mp3Reader != null) { _audio.PlaybackStopped += PreviewAudio_PlaybackStopped; _audio.Play(); } else { Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.FailedToPlayPreviewAudio)} {_audioFileName}")); } NotifyPropertyChanged(nameof(IsPlayingAudio)); } catch (Exception e) { Logger.Error(e); Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.FailedToPlayPreviewAudio)} {_audioFileName}: {e.Message}")); } } else { StopAudio(); } }