private void openFileButton_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();

            pauseButton.Enabled = true;
        }
        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();
                                    
        }
 private void DisposeWave()
 {
     if (output != null)
     {
         if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) output.Stop();
         output.Dispose();
         output = null;
     }
     if (stream != null)
     {
         stream.Dispose();
         stream = null;
     }
 }
 public int EnqueueSamples(int channels, int rate, byte[] samples, int frames)
 {
     if (buffer == null)
     {
         buffer = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat(rate, channels));
         NAudio.Wave.DirectSoundOut dso = new NAudio.Wave.DirectSoundOut(70);
         dso.Init(buffer);
         dso.Play();
     }
     int space = buffer.BufferLength - buffer.BufferedBytes;
     if (space > samples.Length)
     {
         buffer.AddSamples(samples, 0, samples.Length);
         return frames;
     }
     return 0;
 }
 //Dispose the wave
 private void DisposeWave()
 {
     if (output != null)
     {
         //If it's still playing, stop
         if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing)
         {
             output.Stop();
         }
         output.Dispose();
         output = null;
     }
     if (wave != null)
     {
         wave.Dispose();
         wave = null;
     }
 }
        public void playTune(String result)
        {
            string file;
            if (result.Equals("WON"))
            {
                file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\happy.wav";
            }
            else
            {
                file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\sad.wav";
            }

            DisposeWave();

            wave = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
Example #7
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (timer != null)
            {
                timer.Stop();
            }

            if (screenshotTimer != null)
            {
                screenshotTimer.Stop();
            }
            if (waveOut != null)
            {
                waveOut.Stop();
                waveOut.Dispose();
                waveOut = null;
            }
            if (sourceStream != null)
            {
                sourceStream.StopRecording();
                sourceStream.Dispose();
                sourceStream = null;
            }
        }
        //string stopButtonState = "Stop";
        private void play_pause(object sender, EventArgs e)
        {
            if (output == null)
            {
                OpenFileDialog open = new OpenFileDialog();
                open.InitialDirectory = musicDir;
                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();
            }
            else if (output != null)
            {
                if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) output.Pause();
                else if (output.PlaybackState == NAudio.Wave.PlaybackState.Paused) output.Play();
            }
        }
        public Soundsystem()
        {
            NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(
                new NAudio.Wave.Mp3FileReader("sounds/ambience-wind1.mp3"));

            ambience = new NAudio.Wave.BlockAlignReductionStream(pcm);

            pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(
                new NAudio.Wave.Mp3FileReader("music/zombi-drone.mp3"));

            drone = new NAudio.Wave.BlockAlignReductionStream(pcm);

            fire1 = new NAudio.Wave.WaveFileReader("sounds/gun-fire1.wav");
            fire2 = new NAudio.Wave.WaveFileReader("sounds/gun-fire2.wav");
            empty = new NAudio.Wave.WaveFileReader("sounds/gun-empty.wav");
            load = new NAudio.Wave.WaveFileReader("sounds/gun-load.wav");

            hitflesh1 = new NAudio.Wave.WaveFileReader("sounds/hit-flesh1.wav");
            hitflesh2 = new NAudio.Wave.WaveFileReader("sounds/hit-flesh2.wav");
            hitflesh3 = new NAudio.Wave.WaveFileReader("sounds/hit-flesh3.wav");
            hitmetal1 = new NAudio.Wave.WaveFileReader("sounds/hit-metal1.wav");
            hitmetal2 = new NAudio.Wave.WaveFileReader("sounds/hit-metal2.wav");
            hitmetal3 = new NAudio.Wave.WaveFileReader("sounds/hit-metal3.wav");
            hitrock = new NAudio.Wave.WaveFileReader("sounds/hit-rock1.wav");
            hitglass = new NAudio.Wave.WaveFileReader("sounds/hit-glass1.wav");

            walk1 = new NAudio.Wave.WaveFileReader("sounds/walk1.wav");
            walk2 = new NAudio.Wave.WaveFileReader("sounds/walk2.wav");
            walk3 = new NAudio.Wave.WaveFileReader("sounds/walk3.wav");
            walk4 = new NAudio.Wave.WaveFileReader("sounds/walk4.wav");
            walk5 = new NAudio.Wave.WaveFileReader("sounds/walk5.wav");
            walk6 = new NAudio.Wave.WaveFileReader("sounds/walk6.wav");
            walk7 = new NAudio.Wave.WaveFileReader("sounds/walk7.wav");
            walk8 = new NAudio.Wave.WaveFileReader("sounds/walk8.wav");

            zombi1 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan1.wav");
            zombi2 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan2.wav");
            zombi3 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan3.wav");
            zombi4 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan4.wav");
            zombi5 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan5.wav");
            zombi6 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan6.wav");
            zombi7 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan7.wav");

            fire1_channel = new NAudio.Wave.WaveChannel32(fire1);
            fire1_channel.Volume = 0.0f;
            fire2_channel = new NAudio.Wave.WaveChannel32(fire2);
            fire2_channel.Volume = 0.0f;
            load_channel = new NAudio.Wave.WaveChannel32(load);
            load_channel.Volume = 0.0f;
            empty_channel = new NAudio.Wave.WaveChannel32(empty);
            empty_channel.Volume = 0.0f;

            hitglass_channel = new NAudio.Wave.WaveChannel32(hitglass);
            hitglass_channel.Volume = 0.0f;
            hitflesh1_channel = new NAudio.Wave.WaveChannel32(hitflesh1);
            hitflesh1_channel.Volume = 0.0f;
            hitflesh2_channel = new NAudio.Wave.WaveChannel32(hitflesh2);
            hitflesh2_channel.Volume = 0.0f;
            hitflesh3_channel = new NAudio.Wave.WaveChannel32(hitflesh3);
            hitflesh3_channel.Volume = 0.0f;
            hitrock_channel = new NAudio.Wave.WaveChannel32(hitrock);
            hitrock_channel.Volume = 0.0f;
            hitmetal1_channel = new NAudio.Wave.WaveChannel32(hitmetal1);
            hitmetal1_channel.Volume = 0.0f;
            hitmetal2_channel = new NAudio.Wave.WaveChannel32(hitmetal2);
            hitmetal2_channel.Volume = 0.0f;
            hitmetal3_channel = new NAudio.Wave.WaveChannel32(hitmetal3);
            hitmetal3_channel.Volume = 0.0f;

            walk1_channel = new NAudio.Wave.WaveChannel32(walk1);
            walk1_channel.Volume = 0.0f;
            walk2_channel = new NAudio.Wave.WaveChannel32(walk2);
            walk2_channel.Volume = 0.0f;
            walk3_channel = new NAudio.Wave.WaveChannel32(walk3);
            walk3_channel.Volume = 0.0f;
            walk4_channel = new NAudio.Wave.WaveChannel32(walk4);
            walk4_channel.Volume = 0.0f;
            walk5_channel = new NAudio.Wave.WaveChannel32(walk5);
            walk5_channel.Volume = 0.0f;
            walk6_channel = new NAudio.Wave.WaveChannel32(walk6);
            walk6_channel.Volume = 0.0f;
            walk7_channel = new NAudio.Wave.WaveChannel32(walk7);
            walk7_channel.Volume = 0.0f;
            walk8_channel = new NAudio.Wave.WaveChannel32(walk8);
            walk8_channel.Volume = 0.0f;

            zombi1_channel = new NAudio.Wave.WaveChannel32(zombi1);
            zombi1_channel.Volume = 0.0f;
            zombi2_channel = new NAudio.Wave.WaveChannel32(zombi2);
            zombi2_channel.Volume = 0.0f;

            zombi3_channel = new NAudio.Wave.WaveChannel32(zombi3);
            zombi3_channel.Volume = 0.0f;

            zombi4_channel = new NAudio.Wave.WaveChannel32(zombi4);
            zombi4_channel.Volume = 0.0f;

            zombi5_channel = new NAudio.Wave.WaveChannel32(zombi5);
            zombi5_channel.Volume = 0.0f;

            zombi6_channel = new NAudio.Wave.WaveChannel32(zombi6);
            zombi6_channel.Volume = 0.0f;

            zombi7_channel = new NAudio.Wave.WaveChannel32(zombi7);
            zombi7_channel.Volume = 0.0f;

            mikseri = new NAudio.Wave.WaveMixerStream32();

            ambience_channel = new NAudio.Wave.WaveChannel32(ambience);
            ambience_channel.Volume = 0.2f;

            drone_channel = new NAudio.Wave.WaveChannel32(drone);
            drone_channel.Volume = 0.5f;

            mikseri.AddInputStream(fire1_channel);
            mikseri.AddInputStream(fire2_channel);
            mikseri.AddInputStream(empty_channel);
            mikseri.AddInputStream(load_channel);

            mikseri.AddInputStream(hitflesh1_channel);
            mikseri.AddInputStream(hitflesh2_channel);
            mikseri.AddInputStream(hitflesh3_channel);
            mikseri.AddInputStream(hitmetal1_channel);
            mikseri.AddInputStream(hitmetal2_channel);
            mikseri.AddInputStream(hitmetal3_channel);
            mikseri.AddInputStream(hitrock_channel);
            mikseri.AddInputStream(hitglass_channel);

            mikseri.AddInputStream(walk1_channel);
            mikseri.AddInputStream(walk2_channel);
            mikseri.AddInputStream(walk3_channel);
            mikseri.AddInputStream(walk4_channel);
            mikseri.AddInputStream(walk5_channel);
            mikseri.AddInputStream(walk6_channel);
            mikseri.AddInputStream(walk7_channel);
            mikseri.AddInputStream(walk8_channel);

            mikseri.AddInputStream(zombi1_channel);
            mikseri.AddInputStream(zombi2_channel);
            mikseri.AddInputStream(zombi3_channel);
            mikseri.AddInputStream(zombi4_channel);
            mikseri.AddInputStream(zombi5_channel);
            mikseri.AddInputStream(zombi6_channel);
            mikseri.AddInputStream(zombi7_channel);

            mikseri.AddInputStream(ambience_channel);
            mikseri.AddInputStream(drone_channel);

            mikseri.AutoStop = false;

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

            soundson = true;
            output.Play();
        }
        private void stopGame()
        {
            stopProcess();
            jumbledWordLabel.Text = "GAME OVER !";
            answerLabel.Text = "PRESS RESTART\nTO TRY AGAIN !";

            String file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\airhorn.wav";
            wave = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();

            MessageBox.Show("TIME'S UP !");
            MessageBox.Show("Total score: " + points);
        }
Example #11
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;
                }
            }
        }
Example #12
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 buttonStartRecording_Click(object sender, EventArgs e)
        //{
        //    if (listViewAudioSources.SelectedItems.Count == 0) return;

        //    int deviceNumber = listViewAudioSources.SelectedItems[0].Index;

        //    sourceStream = new NAudio.Wave.WaveIn();
        //    sourceStream.DeviceNumber = deviceNumber;
        //    sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);

        //    NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream);

        //    waveOut = new NAudio.Wave.DirectSoundOut();
        //    waveOut.Init(waveIn);

        //    sourceStream.StartRecording();
        //    waveOut.Play();
        //}

        private void buttonStopRecording_Click(object sender, EventArgs e)
        {
            if (waveOut != null)
            {
                waveOut.Stop();
                waveOut.Dispose();
                waveOut = null;
            }
            if (sourceStream != null)
            {
                sourceStream.StopRecording();
                sourceStream.Dispose();
                sourceStream = null;
            }
            if (waveWriter != null)
            {
                waveWriter.Dispose();
                waveWriter = null;
            }
        }
        //Plays/Repeats the audio of the letter
        private void repeatBtn_Click(object sender, EventArgs e)
        {
            String filename = "Class" + LoginForm.classSec + "_kidAudio/" + letters[curPos] + ".wav";
            DisposeWave();

            wave = new NAudio.Wave.WaveFileReader(filename);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
        private void buttonPlayRecording_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Wave File (*.wav)|*.wav;";
            if (open.ShowDialog() != DialogResult.OK) return;
            textBoxRecordingLocation.Text = open.FileName;

            DisposeWave();

            waveReader = new NAudio.Wave.MediaFoundationReader(open.FileName);

            output = new NAudio.Wave.DirectSoundOut();
            //output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Init(waveReader);
            output.Play();
            //pauseButton.Enabled = true;
        }
        private void jollyPicBox_Click_1(object sender, EventArgs e)
        {
            string file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\TeacherWAV\" + lvlStr.ToLower() + ".wav";

            DisposeWave();

            wave = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
        private void jollyPicBox_Click(object sender, EventArgs e)
        {
            string file = "Class" + LoginForm.classSec + "_kidAudio/" + lvlStr.ToLower() + ".wav";

            DisposeWave();

            wave = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
Example #18
0
 private void buttonRecStop_Click(object sender, EventArgs e)
 {
     if (waveOut != null)
     {
         waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if(sourceStream != null)
     {
         sourceStream.StopRecording();
         sourceStream.Dispose();
         sourceStream = null;
     }
     pictureBoxRecording.BackColor = Color.Black;
 }
Example #19
0
        private void buttonRecStart_Click(object sender, EventArgs e)
        {
            if (listViewSources.SelectedItems.Count == 0)
            {
                Console.WriteLine("No device selected.");
                return;
            }

            int deviceNumber = listViewSources.SelectedItems[0].Index;
            labelRecDevice.Text = deviceNumber.ToString();

            sourceStream = new NAudio.Wave.WaveIn();
            sourceStream.DeviceNumber = deviceNumber;
            sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
            sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(waveIn_DataAvailable);
            sourceStream.StartRecording();

            if (checkBoxPlayback.Checked)
            {
                NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream);
                waveOut = new NAudio.Wave.DirectSoundOut(NAudio.Wave.WaveOut.GetCapabilities(outputDevice).ProductGuid);
                waveOut.Init(waveIn);
                waveOut.Play();
            }
            else
            {
                NAudio.Wave.WaveIn waveIn = new NAudio.Wave.WaveIn();
            }

            pictureBoxRecording.BackColor = Color.Red;
        }
Example #20
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;
            }
           
        }
Example #21
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;
            }
        }
 private void DisposeWave()
 {
     if (output != null)
     {
         if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) output.Stop();
         output.Dispose();
         output = null;
     }
     if (waveReader != null)
     {
         waveReader.Dispose();
         waveReader = null;
     }
 }
Example #23
0
        private void playSound(String res)
        {
            string file;
            if (res.Equals("WON"))
            {
                file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\Mario Coin.wav";
            }
            else
            {
                file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\lose.wav";
            }

            DisposeWave();

            wave = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
Example #24
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();
        }
Example #25
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            seconds = seconds - 1;
            if(seconds == 0)
            {
                stopProcess();
                questLabel.Text = "GAME OVER !";
                statusLabel.Text = "PRESS RESTART\nTO TRY AGAIN !";

                String file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\airhorn.wav";
                wave = new NAudio.Wave.WaveFileReader(file);
                output = new NAudio.Wave.DirectSoundOut();
                output.Init(new NAudio.Wave.WaveChannel32(wave));
                output.Play();

                MessageBox.Show("TIME'S UP !");
                MessageBox.Show("Total score: " + points);
            }
            timerLabel.Text = Convert.ToString(seconds);
        }