xamarin.ioscocossharp

Play music in an xamarin ios app developp with CocosSharp


I currently developing an application in ios with Xamarin and I use CocosSharp.

I try to put some Background music on it and I have an exception that always come : "Microsoft.Xna.Framework.Content.ContentLoadException Failed to load the asset file from MySong"

The song is in the content folder : Content/Sounds

To play the sound I use the following line :

CCAudioEngine.SharedEngine.PlayBackgroundMusic("MySong");

I try to change the path, and to reproduce the same way that the music is add in the Fruity Falls Game Details of the Xamarin's site [https://developer.xamarin.com/guides/cross-platform/game_development/cocossharp/fruity_falls/] but nothing is working. Then i try to add music on the Bouncing Game that the code is given in the Xamarin site but it's also does not work.


Solution

  • You need to change the asset file's Build Action. Right-click on the file, scroll to Build Action and ensure that it is set to BundleResource (This is required for iOS projects). Clean/Build the project and try running it again.