Issues developing on Mac

Hey guys, I just started developing using MonoGame on mac and I am a little confused as to the best way to move forward regarding assets. I’ve been able to successfully get my game running on Mac with everything working except for Music. For some reason no matter what I try I can’t get the music to play. The original music files are MP3, I’ve tried leaving using the raw mp3 files, I’ve tried using xnb files generated on Windows (although the output of the build process for the audio files was xnb and wma files side by side). I tried setting up a content project on my Mac but that failed miserably because I am unsure if it should work similar to a content project on windows or what the deal is with that.

I found an mpack on a teamcity server somewhere that I tried to use with Xamarin Studio in order to build my content on mac and this sort of worked since the sprite xnb are usable, none of the audio worked.

I’ve tried looking through the available documentation to try to figure this out but I think I’m getting confused because some of the documentation is outdated and I’m not sure what the current state of things are.

Is there any current (3.2) documentation I can follow in order to get things working using Mac OS as my primary development platform? Is this currently possible to due?

Sorry if this issue has already been addressed or documented somewhere but any guidance is very greatly appreciated. I am also documenting my steps which I will make publicly available once complete so if someone can provide me some hints as to how to get this all setup am I more than willing to fill in the holes and make all steps available publicly once I have everything working end to end.

What platform are you targeting? Are you actually targeting MacOS or just developing on it?

I have sound running in Android and iOS emulators using MonoGame/Xamarin on Mac fine - am using ‘raw’ mp3 files.

Thanks for the reply. Eventually I want to get stuff working on iOS right now I am developing on Mac and attempting to run it on Mac. Did you just leave the .mp3 file instead of the xnb? I tried that but when I loaded the Song and tried MediaPlayer.Play nothing happened, everything in the class was 0’d out. Could it be an issue with how my mp3 files are encoded? What encoding parameters are using?

Thanks again for taking the time to help out!

If you use MGCB (tools/MGCB in the git repo) you can tell it to target mac, and it should output a .xnb and a .aac file

The wiki has some details:

Off the top of my head I think the commandline would be something like:

mono mgcb.exe /platform:MacOSX /build:mymusic.mp3

You can use the same thing to build content for iOS, just change the platform.

I tried using mgcb.exe, I am getting the following error

error: Processor ‘SongProcessor’ had unexpected failure! System.NullReferenceException: Object reference not set to an instance of an object

I issued the following command after building the project : sudo mono MGCB.MacOS.exe /platform:MacOSX /build:level_1_song.mp3

I get the same result running MGCB from either the develop branch or 3.2.

Thanks for the help!

Could you do a bit of debugging and try get a stack trace of where the exception is coming from?
I’m away from my mac at the moment so I can’t help much :slight_smile:

I did some digging, this is what I came up with. I added some additional output where the error occurs.

AudioConverterError audioConvertError;
var converter = AudioConverter.Create(srcFormat, dstFormat, out audioConvertError);

I capture the values of the error, here is what I get.

SrcFormat : [SampleRate=44100 FormatID=MPEGLayer3 FormatFlags=0 BytesPerPacket=0 FramesPerPacket=1152 BytesPerFrame=0 ChannelsPerFrame=2 BitsPerChannel=0]  

DstFormat : [SampleRate=44100 FormatID=MPEG4AAC FormatFlags=0 BytesPerPacket=0 FramesPerPacket=1024 BytesPerFrame=0 ChannelsPerFrame=2 BitsPerChannel=0]

Error : FormatNotSupported

Perhaps those destination parameters are not supported by MPEG4AAC?

@RebelBox - Thanks for reporting this.

The Mac implementation of the content pipeline hasn’t had as much people testing it as the Windows side of things. Having people use it and report problems is critical to seeing these things get fixed.

So please bear with us. :slight_smile:

Tom, no problem at all. Let me know if there is anything I can do to help.

I’ve been looking through some of the documentation to see if I can figure out exactly what the issue is but the documentation on AudioConverter isn’t too explicit about exactly what’s going on underneath the covers. Might have to look at the source to dig further into this.

These values come from AudioConverter.EncodeFormats, and AudioConverter.DecodeFormats.

Encode Format : QUALCOMM
Encode Format : MPEG4AAC
Encode Format : MPEG4AAC_ELD
Encode Format : MPEG4AAC_ELD_SBR
************Divide****************
Decode Format : MPEGLayer1
Decode Format : MPEGLayer2
Decode Format : MPEGLayer3
Decode Format : 1094921523
************Divide****************

Based on the supported encode,decode formats it should work. I have noticed that changing the sample rate doesn’t seems to have any effect. It still thinks the source format is using 44100.

Do you happen to know what version of MonoMac should be used? I have a MonoMac implementation in the Dependencies folder but using that version doesn’t seem to contain all of the audio stuff that is needed so I am currently using the default that gets imported which is the one supplied by Xamarin.

I’ll be sure to report back if I find anything that may be of use.

Thanks again for all the help guys.

I am just leaving the mp3 file, not using xnb. Life’s complicated enough as it is!

Something I did run into with the iOS simulator on the Mac is that it wouldn’t play audio through my audio interface but if I switched to using the default Mac hardware (built-in speakers) it was fine. Something to do with it not being able to get an OpenAL context when my audio interface was being used.

cheers

I’ve still not able to play an mp3 file on MacOSX through OpenAL. I traced through the code and I found that OpenAL is indeed playing the file, it reports that file is being played but there is no audio produced. I looked through some of the extensions reported by OpenAL and noticed the mp3ext was not present. This may be the source of the issue.

I was able to finally play my mp3 file through the use of AVAudioPlayer, I basically did the following:

	NSUrl mp3Path = NSUrl.FromFilename ("Content/Sounds/Music/level_1_song.mp3");
	AVAudioPlayer player = AVAudioPlayer.FromUrl(mp3Path);
	player.PrepareToPlay();
	player.Play();

This seems to be a MacOSX issue since people are reporting that mp3’s work on iOS and other platforms. It seems that I’ll need to wrap my song code to either use monogame implementation on all platforms except for MacOSX until I can figure out why OpenAL refuses to play the sound. I also noticed the the soundeffectinstance created for the song seems to be disposed early if it isn’t played immediately and the duration is not set properly in the Song class but is available through the SoundEffect that is created.

Edit: I’m also using MonoMac and not Xamarin.Mac, perhaps when I switch to that the issue will be resolved.

This was thru the MonoGame MediaPlayer and Song API?

Or are you trying to play an mp3 SoundEffect?

I’m not asking about the internal implementation of MonoGame, I am asking what MonoGame API are you calling.

I don’t know why MonoGame doesn’t use AVAudioPlayer itself for Song on MacOS. Probably it is something newer that wasn’t available when the implementation for Song was done.

Assuming there are not some bad limitations to it that i’m not aware of right now, If someone submits a pull request with a AVAudioPlayer implementation of Song for MacOS we’ll probably accept it.

@Tom Here is a snippet of the code I had previously to switching to AVAudioPlayer.

So, during the initialization of my gamestate I do the following

Song        sgMenuMusic; //Class instance variable. (Private)
sgMenuMusic = Program.theGame.Content.Load<Song>(GameConstants.Chapter1Music);

Then after I’m done loading images, sfx, etc… I do this

 MediaPlayer.Play(sgMenuMusic);

GameConstants.Chapter1Music is a string with the path to the mp3 relative to the content directory. It’s actually able to find the mp3 file and load it, etc… just won’t play through OpenAL (no audio).

I’ll take a stab at switching the MacOSX implementation to use AVAudioPlayer sometime next week. I’ll do some more testing on my end but so far it seems to play nice with OpenAL for sfx.