C# Null Reference Exception Sorunu
-
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; } } -
Player'ı hem global hem button event'ında çağırmışım şimdi farkettim tamamdır :)
Toplam Hit: 1556 Toplam Mesaj: 2
