1

My game works fine in the simulator and on an actual iPod Touch device, but when I run it on my iPad 2 device the sound doesn't play and the sound effects don't play.

Here is my code to start up the background music. Keep in mind this works on the simulator AND on an actual iPod Touch device:

SoundEffect.MasterVolume = 1.0f;

SoundEffect soundMusic = (new ContentManager(screenManager.Game.Services, "Content")).Load<SoundEffect>("Music");
SoundEffectInstance soundMusicInstance = soundMusic.CreateInstance();

soundMusicInstance.IsLooped = true;
soundMusicInstance.Play();

Why doesn't this work on iPad?

mbm
  • 945
  • 9
  • 12
user856232
  • 1,073
  • 2
  • 14
  • 40
  • Just curious, does sound work on this iPad in other apps? Can you try `AVAudioPlayer` as a test to see if it works? (I wouldn't use it in your final game, however, just a test) – jonathanpeppers Aug 15 '12 at 01:52
  • My 2 year old found mute on my iPad the other day. I didn't even know there was such a thing, but it made it look like my iPad couldn't play sound. I think he found it by swiping left after double-tapping the home button. – sblom Aug 15 '12 at 05:30
  • Yes, sound works fine in other apps. I don't know how to use AVAudioPlayer. Is there a way to verify without having to change to that? – user856232 Aug 15 '12 at 05:30
  • It is very simple, try one of the examples here: http://stackoverflow.com/questions/1757768/playing-a-sound-with-monotouch `SystemSound` will work also. – jonathanpeppers Aug 15 '12 at 11:57
  • Did you configure you AudioSession, to notify the OS about the kind of audio that you will be playing back? – miguel.de.icaza Aug 15 '12 at 14:57
  • @miguel.de.icaza: Please tell me about AudioSession. Is that not needed on the simulator and / or the iPod Touch? The sound works fine on those devices. – user856232 Aug 15 '12 at 16:01
  • @jonathanpeppers: I am curious why several people suggestion using those other methods to "test" why sound isn't working. Is there some reason why I should not be using SoundEffect and SoundEffectInstance? Is there some difference between the iPod Touch, iPad and iPad simulator that other APIs solves? I just don't want to spend a bunch of dev time chasing down other APIs if the ones I have chosen are the right ones and should work. – user856232 Aug 15 '12 at 16:02
  • We are trying to see if it is a MonoGame issue, by using Apple's API directly. You should have had enough time to try it out by now. It should be 3 lines of code that you can just throw in where your app starts up. – jonathanpeppers Aug 15 '12 at 21:54
  • I can't get any of these samples to come up with a sound object to play. They all come back null. For example I do this var mediaFile = NSUrl.FromFilename("Music.xnb"); var audioPlayer = AVAudioPlayer.FromUrl(mediaFile); audioPlayer.FinishedPlaying += delegate { audioPlayer.Dispose(); }; audioPlayer.Play (); and audioPlayer is always null. I have the Music.xnb file in a Content folder. How do I make this work so I can even do the test? – user856232 Aug 16 '12 at 04:36
  • From your example, you don't mention they are XNB files. You will have to use an mp3 or wav for the non-MonoGame classes. (This does make me think it might be an issue with MonoGame, what version are you on? 2.5.x (develop) or 3.0 (develop3d) ?) – jonathanpeppers Aug 16 '12 at 12:37
  • Sorry I didn't mention it. I assumed most people used xnb files. Bad assumtion on my part. I have to take this chance to give some BIG KUDOS to everyone working on Mono, MonoTouch and MonoGame. This game is actually a game I did for xBox 360, then I ported it to Windows Phone 7 and using the SAME SOLUTION I now have it on iOS. I didn't have to make very many changes for it to port to iOS. It is already in the market and I have sold many copies. Not a ton, but some. When I first ported it I didn't know you could use the raw .wav files or png files directly because I came from XNA. – user856232 Aug 16 '12 at 13:21
  • So I build my app on Windows and then take the resulting xna files and commit them to the iOS solution. Anyway, so more information, I just copied over the Music.wav file and open it using the same code above and it plays in the simulator. I will have to wait until I get home later to try it out on the iPad. I am using the MonoGame 2.5.0 because that was the last stable version that I knew about when I release Math Gardener II (this game). – user856232 Aug 16 '12 at 13:23
  • I just downloaded MonoGame 2.5.1. I will try it later tonight when I have the iPad. I am going to verify the AV method above works or doesn't before I move on. I like to verify things one at a time. – user856232 Aug 16 '12 at 13:33
  • Ok, word back. I copied the Music.wav file over from the PC project to the iOS project and the following code does NOT work on the actual iPad. On the iPad simulator it DOES work. I CAN play other music and sound on the iPad, so I know it is not a general mute or volume or hardware issue. Here is the code: var mediaFile = NSUrl.FromFilename("Content/Music.wav"); var audioPlayer = AVAudioPlayer.FromUrl(mediaFile); audioPlayer.FinishedPlaying += delegate { audioPlayer.Dispose(); }; audioPlayer.Play (); – user856232 Aug 16 '12 at 22:40
  • I just upgraded to 2.5.1 of MonoGame and reverted back to using the MonoGame code and it works fine in the iPad sim and the actual iPod, but still not joy on the iPad. I am stumped. – user856232 Aug 16 '12 at 22:47
  • We are using SoundEffects in our game on 2.5.1 and not having an issue on iPad. Could you make a quick test project that plays one of your sounds? (it can just clear with cornflower blue for drawing) Also, what version of iOS is this iPad running? – jonathanpeppers Aug 17 '12 at 17:18
  • Seems like that is the next step. I don't have it with me right now, but I know it is not the latest because there is an update available. I will check and get back to you. – user856232 Aug 17 '12 at 21:06

0 Answers0