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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…