0

I am trying to play my music within my game app and it crashes. But when I copy and paste the code within a different xcode project it works?

I'm using a 2d game engine called SpriteKit within Xcode. I play an mp3 file using the AVFoundation framework.

NSURL *url = [[NSBundle mainBundle] URLForResource:@"backgroundMusic" withExtension:@"mp3"];

self.backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];

self.backgroundMusic.numberOfLoops = 1;
[self.backgroundMusic prepareToPlay];

[self.backgroundMusic play];
Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102

1 Answers1

1

AVAudioPlayer throws breakpoint in debug mode

I've had this problem before, this answer helped me:

"Add your exception breakpoint and edit the exception type from "All" to "Objective-C exceptions"

Some classes in AudioToolbox throw regular C++ exceptions. You can filter them off this way."

Community
  • 1
  • 1
Jake Crastly
  • 462
  • 3
  • 9
  • Well it's work not i have a new problem.. I create the AVAudioPlayer object and play the music within the scene, if i transition through to another scene and then go back to the original scene it creates another object and plays the same soundtrack twice. How do i overcome this ? – Shaun Kelly May 01 '15 at 16:00
  • This is a new question, I'll answer it if you make it a seperate stackoverflow question. And remember to accept my answer! – Jake Crastly May 01 '15 at 21:20
  • Here is the link to the questions and i would accept the answer if i had enough reputation. http://stackoverflow.com/questions/30002052/avaudioplayer-not-working – Shaun Kelly May 02 '15 at 12:03