How to play compressed music?

I wanted to add music to my game. First I started with .wav files, but it didn't work, then I converted it to .xnb, but now I get error "This file can not be opened as a file descriptor; it is probably compressed".
Is there a way to play compressed file or decompress it?


  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Can you please provide the original and the .xnb. Also the platforms that you are running against. Each .xnb will probably need to be converted to the specific platform that it will be used on.

    If it would be easier for you then a simple solution of the platforms that you are running against with the music file would be even better.

  • FilipCinikFilipCinik PLMember
    edited August 2015

    I created sample android project. I had to exclude packages, because the solution was too big(200mb). It contains background music converted from .mp3 to .xnb and sound effect converted from .wav to .xnb.
    Preloads are in AppDelegate and play in IntroLayer.
    Background music throws an exception and effect doesn't, but it still doesn't play.

    I forgot to rename file in IntroLayer "sounds/sound_menu_background.mp3" should be "sounds/sound_menu_background.xnb"

  • FilipCinikFilipCinik PLMember

    Any idea? Anyone?

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai


    Slipped through the cracks. I will take a look at the project today.

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Hey Filip

    Not sure what the problem is but have run your project through both Windows (windows 10 and windows 8.1) as well Mac including a couple of devices. Rami tested using his moto g as well.

    Tested using the v1.5.0.1 packages and not from current source base.

    We both made a couple of changes to the source, not sure if they were the same changes but we both changed to run the effect on a touch. On my side I added logging just to make sure any errors were output.

    Here is the ApplicationDidFinishLaunching.

        public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
            CCLog.Logger = System.Diagnostics.Debug.WriteLine;
            application.PreferMultiSampling = false;
            application.ContentRootDirectory = "Content";
            CCSize windowSize = mainWindow.WindowSizeInPixels;
            float desiredWidth = 1024.0f;
            float desiredHeight = 768.0f;
            // This will set the world bounds to be (0,0, w, h)
            // CCSceneResolutionPolicy.ShowAll will ensure that the aspect ratio is preserved
            CCScene.SetDefaultDesignResolution(desiredWidth, desiredHeight, CCSceneResolutionPolicy.ShowAll);
            // Determine whether to use the high or low def versions of our images
            // Make sure the default texel to content size ratio is set correctly
            // Of course you're free to have a finer set of image resolutions e.g (ld, hd, super-hd)
            if (desiredWidth < windowSize.Width)
                CCSprite.DefaultTexelToContentSizeRatio = 2.0f;
                CCSprite.DefaultTexelToContentSizeRatio = 1.0f;
            CCScene scene = new CCScene(mainWindow);
            GameLayer gameLayer = new GameLayer();

    Here is the touches method:

        void OnTouchesEnded(List<CCTouch> touches, CCEvent touchEvent)
            if (touches.Count > 0)
                // Perform touch handling here

    I also created a cross platform PCL project, using v1.5.0.1 package, using Xamarin Studio on Mac and as long as I did not reference the .xnb files, instead used the .mp3 and .wav endings, everything worked on iOS as well.

    So not exactly sure what the problem is.

    Make sure that sound content files are marked as Android Asset.

Sign In or Register to comment.