I am trying to loop my background music in my game however am receiving the error above when putting this if statement in the update function:
if (!songStart)
{
MediaPlayer.Play(backgroundMusic); // error occuring here
songStart = true;
}
when I put this into load content the error dissapears however I need it in the update so that it is constantly checking if the song is not playing (!songstart)
.
I currently have this in load content to load the song:
Song backgroundMusic = Content.Load<Song>("backgroundMusic");
MediaPlayer.IsRepeating = true;
EDIT: Just noticed I am also having the follows error, may this have something to do with it?
'Cannot convert from 'Microsoft.Xna.Framework.Audio.SoundEffect' to 'Microsoft.Xna.Framework.Media.SongCollection'
Thanks.
I don't think you need that bool to check if the audio is already playing, you can use:
if(MediaPlayer.State != MediaState.Playing)
And for your error, you probably have two variables named backgroundMusic
, I think that your class variable is a SoundEffect
(as I read in your previous question), and you have a Song
variable with the same name declared in your LoadContent
. You should remove the first one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.