Domanda

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");
}
È stato utile?

Soluzione

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!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top