Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I keep on getting an "Object reference not set to an instance of an object" message for my code, whilst what I'm trying to do is to initialize a sound that I have embedded in my program on visual studio, a little help please... Thanks :)

What I have tried:

Uri pathToFile = new Uri("pack://application:,,,/clang (1).wav");
StreamResourceInfo strm = Application.GetResourceStream(pathToFile);
SoundPlayer sp = new SoundPlayer(strm.Stream);
sp.PlayLooping();
Posted
Updated 14-Aug-16 16:13pm
v2
Comments
Mehdi Gholam 15-Aug-16 0:28am    
Use a debugger and see which object is null.
Mihlali Ngc 15-Aug-16 1:42am    
I did, the variable strm is null but I don't know how to solve that problem, I've been trying
Mehdi Gholam 15-Aug-16 1:44am    
Then obviously Application.GetResourceStream(pathToFile) isn't working so check you path.
Mihlali Ngc 15-Aug-16 1:56am    
I tried checking, I tried writing the wrong file name, and the message was different, like "file 'clang.wav' was not found, so I knew that it had nothing to do with the file itself as it is part of the project package, but I still don't know where I'm going wrong
Richard MacCutchan 15-Aug-16 3:37am    
That URI does not look valid, you need to check again the absolute path to the file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900