i used three differnet codes, yet it's giving the same error for .wav and .mp3 files
//byte[] file = File.ReadAllBytes(Properties.Resources.Ping2);
Stream stream = new MemoryStream(file);
//plusOneSound = new SoundPlayer(Properties.Resources.Ping2);
// SoundPlayer audio = new SoundPlayer(Dino_endless_runner.Properties.Resources.);
// audio.Play();
Sangeetha SPosted Dec 5, 2024, 11:24 AM
Ensure the byte array is valid: Make sure that
fileis correctly populated with audio data. You can check by logging its length.Use the correct type: If you're using
SoundPlayer, make sure you're passing a valid stream or file path.SoundPlayertypically expects a file path or a stream that is a valid audio format.Check your resource type: If you're using resources from
Properties.Resources, ensure the resource type is correct. ForSoundPlayer, you generally use.wavfiles.Here’s a simple example of how to play a sound from a byte array:
If you're still encountering issues, consider: