Exemple #1
0
        private void button10_Click(object sender, EventArgs e)
        {
            var client   = new MongoClient("mongodb://localhost");
            var database = client.GetDatabase("docs");
            var fs       = new GridFSBucket(database);

            //var aaa = fs.Find()
            var test = fs.DownloadAsBytesByName("Muzika");

            MemoryStream memStream = new MemoryStream(test);

            //OpenFileDialog open = new OpenFileDialog();
            //open.Filter = "Audio File (*.mp3;*.wav)|*.mp3;*.wav;";
            //if (open.ShowDialog() != DialogResult.OK) return;

            DisposeWave();

            // if (open.FileName.EndsWith(".mp3"))
            // {
            NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(memStream));
            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);
            //}
            //else throw new InvalidOperationException("Not a correct audio file type.");

            output = new NAudio.Wave.DirectSoundOut();
            output.Init(stream);
            output.Play();
        }
Exemple #2
0
        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);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Plays sound from start
        /// </summary>
        public void PlaySound()
        {
            if (fileName.EndsWith(".mp3"))
            {
                NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(fileName));
                stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
            }
            else if (fileName.EndsWith(".wav"))
            {
                NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(fileName));
                stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
            }
            else
            {
                throw new InvalidOperationException("Not a correct audio file type. Supports mp3 and wav only!");
            }

            if (output == null)
            {
                output = new NAudio.Wave.DirectSoundOut();
            }

            output.Init(stream);
            output.Play();
        }
Exemple #4
0
 private void gg(string name)
 {
     NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(@"C:\Program Files (x86)\Mektep\sound\" + name));
     stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
     output = new NAudio.Wave.DirectSoundOut();
     output.Init(stream);
 }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {/*Array.Sort();*/
            OpenFileDialog OPPOEpe = new OpenFileDialog();

            OPPOEpe.Filter = "Wawe file (*.mp3|*mp3;) ";
            if (OPPOEpe.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            DisposeWave();
            NAudio.Wave.WaveStream p = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(OPPOEpe.FileName));
            button1.Text = p.WaveFormat.ToString();

            stream = new NAudio.Wave.BlockAlignReductionStream(p);

            TimeSpan error = new TimeSpan(0, 0, 0);

            TimeSpan error1 = new TimeSpan(0, 0, 1);
            TimeSpan error2 = new TimeSpan(1, 0, 1);

            NAudio.Wave.WaveOffsetStream str = new NAudio.Wave.WaveOffsetStream(stream, error, error1, error2);
            gavnout = new NAudio.Wave.DirectSoundOut();
            str.Skip(100);

            gavnout.Init(str);

            gavnout.Play();
        }
Exemple #6
0
        //druga himna
        void output_PlaybackStopped(object sender, NAudio.Wave.StoppedEventArgs e)
        {
            if (notClosed)
            {
                try
                {
                    DisposeWave();

                    byte[]                 gostPesma  = AuxLib.LoadSoundFromGridFS(gost.Ime + "himna");
                    MemoryStream           gostStream = new MemoryStream(gostPesma);
                    NAudio.Wave.WaveStream pcm        = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(gostStream));
                    stream = new NAudio.Wave.BlockAlignReductionStream(pcm);


                    output = new NAudio.Wave.DirectSoundOut();
                    output.Init(stream);

                    output.Play();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
        }
 public void play(string path)
 {
     NAudio.Wave.WaveStream a = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(path));
     NAudio.Wave.BlockAlignReductionStream stream = new NAudio.Wave.BlockAlignReductionStream(a);
     this.output.Init(stream);
     this.output.Play();
 }
        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());
        }
Exemple #9
0
        private void bt_Abrir_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "Audio File (*.mp3;*.wav)|*.mp3;*.wav;";
            if (open.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            DisposeWave();

            if (open.FileName.EndsWith(".mp3"))
            {
                NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(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);
            }
            else
            {
                throw new InvalidOperationException("Not a correct audio file type.");
            }

            output = new NAudio.Wave.DirectSoundOut();
            output.Init(stream);
            output.Play();

            bt_Play_Stop.Enabled = true;
        }
Exemple #10
0
 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);
         }
     }
 }
Exemple #11
0
 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);
         }
     }
 }
Exemple #12
0
        /// <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 void GoalSoundPlay()
        {
            goalSound.Position = 0;
            NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(goalSound));
            stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(stream);
            output.Play();

            Thread.Sleep(3000);
            this.DisposeWave();
        }
Exemple #14
0
        public Main()
        {
            InitializeComponent();
            AMFParser.Initialize();

            /////////////////////////////////////////////////////////////////////////
            /// Setting up automatic audio playback (NAudio)
            MemoryStream mp3file = new MemoryStream(Properties.Resources.ECLiPSE_CyberMotion);

            NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(mp3file));
            NAudio.Wave.BlockAlignReductionStream stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
            NAudio.Wave.DirectSoundOut            output = new NAudio.Wave.DirectSoundOut(700); //audio latency (to stop crackling)
            output.PlaybackStopped += (pbss, pbse) => { System.Threading.Thread.Sleep(1000); stream.Position = 0; output.Play(); };
            output.Init(stream);
            output.Play();
            /////////////////////////////////////////////////////////////////////////

            //users.dat holds captured usernames and uuids locally
            //format: username > xxxxx-xxxx-xxx...(36 character uuid)

            if (!File.Exists("users.dat"))
            {
                File.Create("users.dat").Close();
            }

            foreach (string line in File.ReadAllLines("users.dat"))
            {
                uuid_combobox.Items.Add(line);
            }

            if (uuid_combobox.Items.Count > 0)
            {
                uuid_combobox.SelectedIndex = 0;
            }

            //gets and lists all available network interfaces
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface nic in nics)
            {
                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    adapter_combobox.Items.Add(String.Format("{0}: {1}", nic.Name, nic.Id));
                }
            }

            if (adapter_combobox.Items.Count > 0)
            {
                adapter_combobox.SelectedIndex = 0;
            }
        }
Exemple #15
0
        private void button9_Click(object sender, EventArgs e)
        {
            FileStream     Tstream;
            OpenFileDialog ofd      = new OpenFileDialog();
            var            client   = new MongoClient("mongodb://localhost");
            var            database = client.GetDatabase("docs");
            var            fs       = new GridFSBucket(database);

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Tstream = new System.IO.FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
                //SoundPlayer simpleSound = new SoundPlayer(stream);
                //simpleSound.Play();
                var split = ofd.SafeFileName.Split('.');
                if (split[1] != "mp3")
                {
                    MessageBox.Show("Izaberite mp3 fajl!");
                    return;
                }
                DisposeWave();

                NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(Tstream));
                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);
                //}
                //else throw new InvalidOperationException("Not a correct audio file type.");

                output = new NAudio.Wave.DirectSoundOut();
                output.Init(stream);
                output.Play();

                //GridFSUploadOptions opcije = new GridFSUploadOptions();
                //opcije.ContentType = "audio/mp3";
                //opcije.ChunkSizeBytes = Convert.ToInt32(stream.Length)/4;

                //int duzina = Convert.ToInt32(stream.Length);
                //byte[] bajtovi = new byte[duzina];
                //stream.Seek(0, SeekOrigin.Begin);
                //int bytesRead = stream.Read(bajtovi, 0, duzina);

                //fs.UploadFromBytes(ofd.SafeFileName, bajtovi, opcije);
                //FormaPesma = ofd.SafeFileName;
            }
        }
Exemple #16
0
 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);
 }
Exemple #17
0
        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "MP3 File (*.mp3)|*.mp3;";
            if (open.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            DisposeWave();

            NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(open.FileName));
            stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(stream);
            output.Play();
            pauseMP3Button.Enabled = true;
        }
Exemple #18
0
        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "MP3 File (*.mp3|*.mp3;";
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }



            NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(dialog.FileName));
            NAudio.Wave.BlockAlignReductionStream stream = new NAudio.Wave.BlockAlignReductionStream(pcm);

            NAudio.Wave.DirectSoundOut output = new NAudio.Wave.DirectSoundOut();
            output.Init(stream);
            output.Play();
        }
Exemple #19
0
        private void FInfoZaMec_Load(object sender, EventArgs e)
        {
            try
            {
                //TO DO : UCITATI I FORMATIRATI INFORMACIJE O OBA TIMA I O STADIONU I UPISATI U RTB..
                //prvo za domacina
                AuxLib.PrikaziDomacinaRTB(RTBDomacinInfo, domacin.Ime);
                AuxLib.PrikaziGostaRTB(RTBGostInfo, gost.Ime);
                AuxLib.PrikaziStadionRTB(RTBStadionInfo, stadion.Ime);



                //-------------------------

                //ucitavanje slika iz gridFS-a
                this.PBDomacinZastava.Image = AuxLib.LoadImageFromGridFS(domacin.Ime + "zastava");
                this.PBGostZastava.Image    = AuxLib.LoadImageFromGridFS(gost.Ime + "zastava");
                this.PBStadionZastava.Image = AuxLib.LoadImageFromGridFS(stadion.Ime + "stadion");
                //--------------------------

                //ucitamo himnu iz baze kao byte array
                byte[] domacinPesma = AuxLib.LoadSoundFromGridFS(domacin.Ime + "himna");
                //napravis stream
                MemoryStream domacinStream = new MemoryStream(domacinPesma);
                //prekines ako ima neka pesma prethodno ( za svaki slucaj );
                DisposeWave();
                //pcm pd strima
                NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(domacinStream));
                stream = new NAudio.Wave.BlockAlignReductionStream(pcm);

                //init,hendler za drugu himnu i play
                output = new NAudio.Wave.DirectSoundOut();
                output.Init(stream);
                output.PlaybackStopped += output_PlaybackStopped;
                output.Play();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Exemple #20
0
        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");
        }
Exemple #21
0
        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 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);
        }
Exemple #23
0
        private void FInfoZaMec_Load(object sender, EventArgs e)
        {
            try
            {
                //vraca vraca objekte i upisuje podatke u richtextboxove
                domacin = AuxLib.PrikaziDomacinaRTB(this.RTBDomacinInfo, domacinIme);
                gost    = AuxLib.PrikaziDomacinaRTB(this.RTBGostInfo, gostIme);
                stadion = AuxLib.PrikaziStadionRTB(this.RTBStadionInfo, domacin);
                //-------------------------

                //ucitavanje slika iz gridFS-a
                this.PBDomacinZastava.Image = AuxLib.LoadImageFromGridFS(this.domacinIme + "zastava");
                this.PBGostZastava.Image    = AuxLib.LoadImageFromGridFS(this.gostIme + "zastava");
                this.PBStadionZastava.Image = AuxLib.LoadImageFromGridFS(stadion.Ime + "stadion");
                //--------------------------

                //ucitamo himnu iz baze kao byte array
                byte[] domacinPesma = AuxLib.LoadSoundFromGridFS(domacinIme + "himna");
                //napravis stream
                MemoryStream domacinStream = new MemoryStream(domacinPesma);
                //prekines ako ima neka pesma prethodno ( za svaki slucaj );
                DisposeWave();
                //pcm pd strima
                NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(domacinStream));
                stream = new NAudio.Wave.BlockAlignReductionStream(pcm);

                //init,hendler za drugu himnu i play
                output = new NAudio.Wave.DirectSoundOut();
                output.Init(stream);
                output.PlaybackStopped += output_PlaybackStopped;
                output.Play();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
        private void lstSongBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            foreach (Song find in songDll)
            {
                if (lstSongBox.SelectedItem.ToString() == find.gsSongName)
                {
                    DisposeWave();
                    //check if mp3 or wav
                    if (find.gsSongURL.EndsWith(".mp3"))
                    {
                        //take the pcm data into a new stream and play the mp3 file
                        NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(find.gsSongURL));
                        stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
                    }
                    else if (find.gsSongURL.EndsWith(".wav"))
                    {
                        //do the same as the above but with a wav file
                        NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(find.gsSongURL));
                        stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
                    }
                    else
                    {
                        throw new InvalidOperationException("Not a correct audio file type");
                    }
                    output = new NAudio.Wave.DirectSoundOut();
                    output.Init(stream);
                    output.Play();

                    btnPlay.IsEnabled  = true;
                    btnStop.IsEnabled  = true;
                    btnPause.IsEnabled = true;

                    txtNowPlaying.Text = "Now playing: " + lstSongBox.SelectedItem.ToString();
                }
            }
        }
Exemple #25
0
        //bwMusic
        void bwMusic_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (MusicToTable[songPlayed].currentMedia.getItemInfo("FileType") == "mp3") //check for extension
                {
                    pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader((string)e.Argument));
                }
                else
                {
                    e.Cancel = true;
                    object obj = new object();
                    EventArgs evt = new EventArgs();
                    playStopMusic(obj, evt);
                    MessageBox.Show("I can not send wav files to server. Please try mp3 files.");
                    return;
                }
                int oneSec = 1204 * 4;  //1204 samples * 2 channels * 2 bytes each
                byte[] buffer = new byte[oneSec];
                int ret = 0;

                do
                {
                    if (bwMusic.CancellationPending)
                    {
                        pcm.Dispose();
                        e.Cancel = true;
                        return;
                    }
                    if (pcm != null)
                        ret = pcm.Read(buffer, 0, oneSec);
                    if (ns != null)
                        ns.Write(buffer, 0, oneSec);
                } while (ret >= 0);
                pcm.Dispose();

            }
            catch
            {
                connectedToServer = false;
                if (bwMusic.IsBusy)
                    bwMusic.CancelAsync();
                if (bwMusic2.IsBusy)
                    bwMusic2.CancelAsync();
                MessageBox.Show("Something went wrong with the server");
            }
        }
Exemple #26
0
            public SFXNode(string title)
            {
                done = false;
                fx_in = null;
                fx_out = null;
                this.title = title;
                string path = Program.tools + "sfx\\" + title;

                if (File.Exists(path + ".mp3"))
                {
                    fx_in = new NAudio.Wave.Mp3FileReader(path + ".mp3");
                }
                else
                {
                    fx_in = new NVorbis.NAudioSupport.VorbisWaveReader(path + ".ogg");
                }
                fx_out = new NAudio.Wave.WasapiOut(LSSettings.singleton.devRec.mm, NAudio.CoreAudioApi.AudioClientShareMode.Shared, false, 100);
                fx_out.PlaybackStopped += new EventHandler<NAudio.Wave.StoppedEventArgs>(fx_out_PlaybackStopped);
                fx_out.Init(fx_in);
                fx_out.Play();
            }
 /// <summary>
 /// Creates a new Loop stream
 /// </summary>
 /// <param name="sourceStream">The stream to read from. Note: the Read method of this stream should return 0 when it reaches the end
 /// or else we will not loop to the start again.</param>
 public LoopStream(NAudio.Wave.WaveStream sourceStream)
 {
     this.sourceStream  = sourceStream;
     this.EnableLooping = true;
 }