实现声音,震动

.m.文件中

-(BOOL)testMe{

    

    NSError *error;

    NSString *path = [[NSBundle mainBundle] pathForResource:@"apple" ofType:@"mp3"];

    if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {

        return NO;

    }

    

    player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];

    

    if (!player) {

        return NO;

    }

    [player play];

    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

    

    for (int i=9; i>0; i--) {

        player.volume = i;

        [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5f]];

    }

    [player pause];

    

    return YES;

}

你可能感兴趣的:(实现声音,震动)