I am using a UIImagePickerController for recording a 30 second video.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.videoMaximumDuration=30.0f;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self presentViewController:picker animated:YES completion:NULL];
I want an alarm type notification for user to notify user that video recording time is about to complete.
For example, if my timer for video recording completes 25s then an alarm is started for notifying user that video recording is about to finish at 30 seconds.
Using videoMaximumDuration method you can restrict length of video from both ways. Like if you are recording video an alert will popup saying you cannot record video more than 60 sec and if you are selecting any video file from your library, first it will check the length of your video if length is more than 60 sec. Again alert will popup saying video is larger than 60 sec but there will be two options i.e. use or cancel. If you select use then it will crop the length of video upto 60sec from the beginning.
imagePickerController.videoMaximumDuration = 60.0f;
Related
I have a MPMediaPickerController showing songs available on the device to use for sending to other users on my app. I've filtered out Cloud items, but I also want to filter out songs from Apple Music that have been made "available offline."
-(void)openMusic:(NSNotification *)notification {
if ([[notification name] isEqualToString:#"myMusic"]){
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.75 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = NO;
mediaPicker.showsCloudItems = NO;
[self presentViewController:mediaPicker animated:YES completion:nil];
});
}
}
Currently, it's still showing all downloaded Apple Music tracks. How can I filter them out?
According to this answer, if you use:
picker.showsCloudItems = NO;
You will get the list of songs that either were manually downloaded in the Music app or songs that were streamed and therefore cached.
However, since Apple Music songs are DRM protected, to display only songs downloaded locally, you need to add this line, too:
picker.showsItemsWithProtectedAssets = NO;
How to continue picking video from photo library in background mode ?
I mean when I press use button from imagePickerController - PhotoLibrary and video is started to get compressing - During this compression process (have attached screenshot) if I press home button(i.e. go to background) and then come to foreground then I got info[UIImagePickerControllerMediaURL] as null, so is it possible that app can continue compressing video in background also and return proper url when come to foreground ?
Screenshot :
My didFinishPickingMediaWithInfo,
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSURL *url = info[UIImagePickerControllerMediaURL];
NSLog(#"url : %#",url);
[picker dismissViewControllerAnimated:YES completion:nil];
}
P.S : If we record video by camera and go to background then it will stop recording there and we can use it after coming foreground.
I have thought of one workaround - UIBackgroundTaskIdentifier but it will not work in every case, if video is big then it have time limit, so looking for any other solution!
Any help will be appreciated! :)
IF we want to pick video continuously in background by UIImagePickerController from photolibrary during video is compressing and user press home button(app go in background) then we have to use UIBackgroundTaskIdentifier for continue execution in background or any other background way which keeps app working in background(less possible thing!). Now, UIBackgroundTaskIdentifier has time limit so we can't pick any size of video, so if we restricted video time duration then we can pick it continuously in background something like,
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.videoMaximumDuration = 60.0;
self.backgroundTask = UIBackgroundTaskInvalid;
self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
NSLog(#"Background handler called. Not running background tasks anymore.");
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
}];
[self presentViewController:picker animated:YES completion:NULL];
With UIImagePickerController we can do that much only to pick video in background. If anyone want to pick large video in background then he/she should take look into ALAssetLibrary or Photos framework.
I am building an application that plays certain video files. However, when the phone is on vibrate the audio still plays. Apps like youtube still play the audio form their videos when the phone is on vibrate. How can I do this? I am using avplayer to play the video. Below is my code for playing the video
_player = [[AVPlayer alloc]initWithPlayerItem:pi];
AVPlayerViewController *playerController = [[AVPlayerViewController alloc]init];
playerController.player = _player;
[self presentViewController:playerController animated:YES completion:nil];
playerController.view.frame = self.view.frame;
[_player setMuted:false];
[self addChildViewController:playerController];
Found the solution. Adding this code allows whatever video is playing to produce audio even on silent mode.
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error: nil];
I have implemented to launch UIImagePickerController to capture picture. At the first time, rear camera appear fast, then I switch to front camera, it responses very slowly. It seems to take me nearly 15 seconds. I don't know why initing front camera so slow.
Here my code
UIImagePickerController * _picker = nil;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
_picker = [[[UIImagePickerController alloc] init] autorelease];
_picker.delegate = self;
_picker.allowsEditing = NO;
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:_picker animated:YES];
}
UPDATE: My device is iPad 2 (iOS 7.0), I also test Facebook app on my device, it responses immediately when I switch to front camera. When I test my app on Ipad mini (iOS 6.1.3), it works very well, this problem doesn't happen. Can someone figure me out, it's little missing when initialize UIImagePickerController, I suppose.
UPDATE 2: I wrote an another very simple project. It launches an UIImagePickerController immediately on viewDidLoad of the rootViewController and it works well, UIImagePickerController responses instantly when I switch to front camera. Does anyone have idea for it?
Do this on new thread would cancel the delay on open url. I bet it is the same delay.
Note: Not yet tested on camera.
[NSThread detachNewThreadSelector:#selector(openbrowser_in_background:) toTarget:self withObject:Object];
- (void)openbrowser_in_background:(NSString *)url
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]];
}
And you might like to change the openURL to
[self presentModalViewController:_picker animated:YES];
I am playing a video with mpmovieplayer, but I need to know when the video has loaded completely so I can turn off the network activity indicator. is there a notification that would tell me when the video is completely loaded?
I was thinking the four load states would help:
MPMovieLoadStateUnknown
MPMovieLoadStatePlayable
MPMovieLoadStatePlaythroughOK
MPMovieLoadStateStalled
I tried the playthroughok load state but that doesn't tell me when the video is completely loaded.
Here is some of my .m code for my video player:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:self.videoitem];
self.moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
self.moviePlayer.view.frame = CGRectMake(0, 0,320, 480);
[self.view addSubview:self.moviePlayer.view];
}
Thank you for your help!