how to play audio file when imageview is at some position on screen which is moving by accelerometer
In my project i am trying to play when my image is moving from one side to another side of half of horizontal screen .
i am trying like this
sample code
- (void)accelerometer:(UIAccelerometer *)acel
didAccelerate:(UIAcceleration *)acceleration {
if (imageView.center.x + translation.x > 160 - ballRadius) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"warning" ofType:@"m4r"];
NSURL *file = [[NSURL alloc] initFileURLWithPath:path];
AVAudioPlayer *p =[[AVAudioPlayer alloc]
initWithContentsOfURL:file error:nil];
[file release];
self开发者_开发技巧.player = p;
[p release];
[player prepareToPlay];
[player setDelegate:self];
[self.player play];
}
}
but my app is crashing when i am trying like this
can any one please help me
regards
Where is your app crashing? Did you use the Debugger to determine where?
How many times per second is this accelerometer being called? If you are trying to start the same sound that many times, it may be too much for the AVPlayer.
精彩评论