2
\$\begingroup\$

I'm trying to play a song in a MonoGame project, but it always gives me a weird error. Here is the (Very simple) code:

Song song = Content.Load<Song>("Song1");
        MediaPlayer.Play(song);

But whenever I run the program, it says this:

System.InvalidCastException: 'Unable to cast object of type 'Microsoft.Xna.Framework.Audio.SoundEffect' to type 'Microsoft.Xna.Framework.Media.Song'.'

Do you know why this happens? Any help would be appreciated! :D

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

I believe the content importers are set up in a way that any .wav file must be loaded as a SoundEffect, and any .mp3 or .wma file must be loaded as a Song.

Your best bet is probably to convert the file to an .mp3, or load and play your music as a SoundEffect.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .