tocando sons aleatórios em um aplicativo de soundboard
Eu tenho tentado criar um aplicativo que, quando eu pressiono um botão, ele toca um som, mas quando eu pressiono o mesmo botão, ele toca um som diferente. Eu não me importo se ele toca aleatoriamente o tempo todo ou se toca um som diferente uma vez, mas a mesma ordem toda vez que espero que isso faça sentido caras
Aqui está todo o código que tenho:
.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@class AVAudioPlayer;
@interface ViewController : UIViewController
-(IBAction)PlayRandomSound;
@property (nonatomic, retain) AVAudioPlayer *soundPlayer;
@end
.m
#import "ViewController.h"
#import <AVFoundation/AVAudioPlayer.h>
@interface ViewController ()
@end
@implementation ViewController
@synthesize soundPlayer = _soundPlayer;
-(IBAction)PlayRandomSound{
int randomNumber = arc4random() % 8 + 1;
NSURL *soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"Sound%02d", randomNumber] ofType:@"mp3"]];
_soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];
[_soundPlayer prepareToPlay];
[_soundPlayer play];
NSLog(@"randomNumber is %d", randomNumber);
NSLog(@"tmpFilename is %@", soundURL);
}
Aqui os erros que tenho nas imagens
Eu também inseri o AVFoundation.Framework e AudioToolbox.Frame