Giriş Yap Kayıt ol Online Üyeler Aktif Konular Arama Üyeler Forum Kuralları
Tahribat.Com | C# Null Reference Exception Sorunu
Tahribat.Com Forumları
Asp.Net - C#.Net - J#.Net - Vb.Net
      C# Null Reference Exception Sorunu
Bu Bölümde yeni konu açmak için tıklayın Konuyu cevaplamak için tık...
Konu 6 Subat 2012 (Pazartesi) 03:56 tarihinde açıldı. Kısayol | Alıntı yap | Özel Mesaj
SinusX


Kayıt : 14 Aralik 2010
[-1,1]
Erkek Üye
 

Normal form.cs içerisinde sorunsuz çalışan fonksiyonlar Player.cs diye sınıf oluşturup çağırdığımda Null Reference Exception yiyorum bu neden olabilir ?

Pause dediğimde ve Kill dediğimde waveOutDevice veriyor hatayı

 

 

private void button1_Click(object sender, EventArgs e)
        {
            Play("C:\\Users\\SinusX\\Desktop\\Hit MP3\\Moves Like Jagger - Maroon 5 featuring Christina Aguilera.mp3");
        }


        private void button2_Click(object sender, EventArgs e)
        {
            Pause();
        }


        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Kill();
        }


        WaveStream mainOutputStream;
        WaveChannel32 volumeStream;
        IWavePlayer waveOutDevice;

        public void Play(string path)
        {
            waveOutDevice = new WasapiOut(AudioClientShareMode.Shared, 100);
            mainOutputStream = CreateInputStream(path);
            waveOutDevice.Init(mainOutputStream);
            waveOutDevice.Play();
        }

        public void Pause()
        {
            if (waveOutDevice.PlaybackState == PlaybackState.Playing)
            {
                waveOutDevice.Pause();
            }
            else
            {
                waveOutDevice.Play();
            }
        }

        private WaveStream CreateInputStream(string path)
        {
            WaveChannel32 inputStream;
            if (path.EndsWith(".mp3"))
            {
                WaveStream mp3Reader = new Mp3FileReader(path);
                inputStream = new WaveChannel32(mp3Reader);
            }
            else
            {
                throw new InvalidOperationException("Unsupported extension");
            }
            volumeStream = inputStream;
            return volumeStream;
        }

        public void Kill()
        {
            if (waveOutDevice != null)
            {
                waveOutDevice.Stop();
            }
            if (mainOutputStream != null)
            {
                // this one really closes the file and ACM conversion
                volumeStream.Close();
                volumeStream = null;
                // this one does the metering stream
                mainOutputStream.Close();
                mainOutputStream = null;
            }
            if (waveOutDevice != null)
            {
                waveOutDevice.Dispose();
                waveOutDevice = null;
            }
        }

... 
6 Subat 2012 (Pazartesi) 04:05 tarihinde yazıldı. Kısayol | Alıntı yap | Özel Mesaj
SinusX


Kayıt : 14 Aralik 2010
[-1,1]
Erkek Üye
 

Player'ı hem global hem button event'ında çağırmışım şimdi farkettim tamamdır :)


... 

[1]


Bu Bölümde yeni konu açmak için dıklayın Konuyu cevaplamak için tık...
Allah'a Havale Et Google Bookmark'a Ekle Yahoo'ya Ekle Stumbleupon'a Ekle Facebook'a Ekle Twitter'a Ekle   Google'da Ara : C# Null Reference Exception Sorunu Favorilerime Ekle Yukarı Çık
Konuda 2 Mesaj Var.
Konu 129 Sefer Gösterilmiş.
2001-2012 © Tahribat Group - Her Hakkı Saklıdır. - ● Gizlilik İlkeleri ● Kullanım Koşulları ● İletişim