这是一个新手问题。iOS按钮无法播放按钮水龙头上的音频文件
我有一个非常简单的应用程序是应该当主视图按钮被窃听只播放音频文件。
我使用的XCode 4.6版。
我增加了一个音频文件“audioclip.wav”我的项目。我已添加AVFoundation.framework
。
我的项目只有ViewController.h
和ViewController.m
。
我双击并使用助理编辑器创建我的IBAction
连接从按钮拖在故事板.h文件。
我ViewController.h:
#import <UIKit/UIKit.h>
#import<AVFoundation/AVAudioPlayer.h>
@interface ViewController : UIViewController <AVAudioPlayerDelegate> {
}
- (IBAction)playAudio:(id)sender;
@end
我ViewController.m:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (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.
}
- (IBAction)playAudio:(id)sender {
AVAudioPlayer *audioPlayer;
NSString *audioPath = [[NSBundle mainBundle] pathForResource:@"audioclip" ofType:@"wav" ];
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:nil];
[audioPlayer play];
}
@end
无论出于何种原因(可能是一些愚蠢的我离开了)的audioclip.wav文件不,当我点击播放按钮。我已经在iPhone 6.1模拟器和我的设备上进行了测试。
检查IBOutlet中和按钮操作? – Balu 2013-04-22 04:18:05
@ brno792检查您是否在TouchUpInside方法上连接了按钮。 – 2013-04-22 04:21:28
看到我的答案.. http:// stackoverflow。com/questions/16033723/audio-file-not-working-on-device-but-it-is-working-on-simulator/16033796#16033796 – 2013-04-22 04:23:12