lundi 24 mars 2014

Sound not playing in iOS Simulator. No errors


Vote count:

0




I have constructed some code that is supposed to play audio when a button is clicked. There are no errors in the code, but when I open the iOS Simulator and press the button, no sound plays. The button does the tap animation, but nothing happens. I have both the AVFoundation and AudioToolbox frameworks. I also have my audio file in resources. I am not using breakpoints. The button is set to use the 'playAudio:' first responder upon Touch Up Inside.


Here is my 'ViewController.h' file:



#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>

@interface ViewController : UIViewController

@property (strong, nonatomic) AVAudioPlayer *audioPlayer;
- (IBAction)playAudio:(id)sender;

@end


And here is my 'ViewController.m' file:



#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>

@interface ViewController ()

@end

@implementation ViewController

- (IBAction)playAudio:(id)sender {
AVAudioPlayer *audioPlayer;
NSString *audioPath = [[NSBundle mainBundle] pathForResource:@"AudioFile" ofType:@"wav"];
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:nil];
[audioPlayer play];
sleep(5);
};

-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end


The audio segment is about 3 seconds.


Any help is much appreciated! Thanks!



asked 42 secs ago






Aucun commentaire:

Enregistrer un commentaire