سؤال

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");
}
هل كانت مفيدة؟

المحلول

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!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top