how to use Vibration while recording iphone5 IOS?

2019-01-20 12:05发布

问题:

I am working on a iphone5 app and i need some advice on the vibration motor. i goggled the things but cant find how can i manually rotate my iPhone from the code.please guide me... or give any link or ideas..

What i want to do is vibrate the phone while recordign the video .

but my problem is when i start the vibration it cant recrod the video.. i found that it will not work when audio is capturing running.. so i tried with mute the sound while recording but its not working still

following is my code..

//
//  APPViewController.m
//  
//
//  Created by Rafael Garcia Leiva on 29/04/13.
//  Copyright (c) 2013 Appcoda. All rights reserved.
//

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

@interface APPViewController ()

@end

@implementation APPViewController

- (void)viewDidLoad {

    [super viewDidLoad];



}

- (void)viewDidAppear:(BOOL)animated {

    self.movieController = [[MPMoviePlayerController alloc] init];
    [self.movieController setContentURL:self.movieURL];

    [self.movieController.view setFrame:CGRectMake ( 0, 0, 320, 476)];

    [self.view addSubview:self.movieController.view];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(moviePlayBackDidFinish:)
                                          name:MPMoviePlayerPlaybackDidFinishNotification
                                          object:self.movieController];

    [[MPMusicPlayerController applicationMusicPlayer] setVolume:0];

    [self.movieController play];

    [self setupAudio];



}

- (IBAction)takeVideo:(UIButton *)sender {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];




    [self presentViewController:picker animated:YES completion:NULL];
    while(TRUE){

        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

    }



}

- (void)setupAudio {
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
    UInt32 doSetProperty = 1;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty);
    [[AVAudioSession sharedInstance] setActive: YES error: nil];
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    self.movieURL = info[UIImagePickerControllerMediaURL];

    [picker dismissViewControllerAnimated:YES completion:NULL];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [picker dismissViewControllerAnimated:YES completion:NULL];

}

- (void)moviePlayBackDidFinish:(NSNotification *)notification {

    [[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    [self.movieController stop];
    [self.movieController.view removeFromSuperview];
    self.movieController = nil;

}

@end

i am vibrating my phone with this but its working vibrating or video recording...if video will record with no sound then even its ok for me..

while(TRUE){

        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

    }

thanks

回答1:

I'm guessing the recording APIs might internally disable vibration (and other system sounds too) because vibration during recording would seriously degrade the video and audio quality of the recording.

Of course I'm only guessing. That seems like the sort of thing Apple might do, and I think in most cases that's what you would want (e.g., you wouldn't want a recording to be ruined by an incoming text message or phone call). I'm curious why you want to vibrate the device during recording - is it for a special effect?