Question

so I have the code shown but my music is not playing and I'm not sure why. the sound on my computer is turned up xcode can play the file that i imported in.

-(void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    NSError *error;
    NSLog(@"starting Music");
    NSURL * backgroundMusicURL = [[NSBundle mainBundle] URLForResource:@"rainbowRoad" withExtension:@"m4a"];
    self.backgroundMusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundMusicURL error:&error];
    self.backgroundMusicPlayer.numberOfLoops = -1;
    [self.backgroundMusicPlayer prepareToPlay];
    [self.backgroundMusicPlayer play];
    NSLog(@"awesome");
}
Was it helpful?

Solution

I don't think your sound file is being copied. Select your audio file in Xcode, then in the File Inspector's Target Membership section, make sure your target is checked.

Check this thing!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top