0
所以我試圖用視圖的連接來啓動一個伴有搖動的聲音文件。我的代碼拋出錯誤沒有可見@interface爲'AVAudioPlayer'聲明選擇器'播放'。使用AVAudioPlayer嘗試使用運動手勢不起作用
這是ViewController.m
#import "aniMateViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
@interface aniMateViewController()
@end
@implementation aniMateViewController
@synthesize playSound;
-(BOOL)canBecomeFirstResponder
{
return YES;
}
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake)
{ NSLog(@"Device started shaking!");
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/play.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 0;
[audioPlayer playSound];
}
}
的.h文件在這裏
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
@interface aniMateViewController : UIViewController
{
AVAudioPlayer *audioPlayer;
IBOutlet UIView *start;
}
@property (weak, nonatomic) IBOutlet UIView *playSound;
@end
任何建議??? –