Starting in iOS 3.0, you can record video, with included audio, on supported devices. To display the video recording interface, create and push a UIImagePickerController object, just as for displaying the still-camera interface.
To record video, you must first check that the camera source type (UIImagePickerControllerSourceTypeCamera) is available and that the movie media type (kUTTypeMovie) is available for the camera. Depending on the media types you assign to themediaTypes property, the picker can directly display the still camera or the video camera, or a selection interface that lets the user choose.
Using the UIImagePickerControllerDelegate protocol, register as a delegate of the image picker. Your delegate object receives a completed video recording by way of the imagePickerController:didFinishPickingMediaWithInfo: method.
On supported devices, you can also pick previously-recorded videos from a user’s photo library.
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *pickerController = [[UIImagePickerControlleralloc]init];
pickerController.sourceType =UIImagePickerControllerSourceTypeCamera;
// + (NSArray *)availableMediaTypesForSourceType:(UIImagePickerControllerSourceType)sourceType;
pickerController.mediaTypes = [NSArrayarrayWithObject:@"public.movie"];
pickerController.cameraCaptureMode =UIImagePickerControllerCameraCaptureModeVideo;
pickerController.delegate = self;
[selfpresentViewController:pickerControlleranimated:YEScompletion:Nil];
}
// 访问库中的视频
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *pickerController = [[UIImagePickerControlleralloc] init];
pickerController.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
pickerController.mediaTypes = [NSArrayarrayWithObject:@"public.movie"];
pickerController.delegate = self;
[selfpresentViewController:pickerController animated:YEScompletion:Nil];
}
For information on trimming recorded videos, see UIVideoEditorController Class Reference and UIVideoEditorControllerDelegate Protocol Reference.
In iOS 4.0 and later, you can record from a device’s camera and display the incoming data live on screen. You useAVCaptureSession to manage data flow from inputs represented by AVCaptureInput objects (which mediate input from anAVCaptureDevice) to outputs represented by AVCaptureOutput.
In iOS 4.0 and later, you can edit, assemble, and compose video using existing assets or with new raw materials. Assets are represented by AVAsset, which you can inspect asynchronously for better performance. You use AVMutableComposition to compose media from one or more sources, then AVAssetExportSession to encode output of a composition for delivery.
Playing Video Files
OS supports the ability to play back video files directly from your application using the Media Player framework, described inMedia Player Framework Reference.
Playing full-screen movies
-(void) playMovieAtURL: (NSURL*) theURL { |
| |
MPMoviePlayerController* theMovie = |
[[MPMoviePlayerController alloc] initWithContentURL: theURL]; |
| |
theMovie.scalingMode = MPMovieScalingModeAspectFill; |
theMovie.movieControlMode = MPMovieControlModeHidden; |
| |
// Register for the playback finished notification |
[[NSNotificationCenter defaultCenter] |
addObserver: self |
selector: @selector(myMovieFinishedCallback:) |
name: MPMoviePlayerPlaybackDidFinishNotification |
object: theMovie]; |
| |
// Movie playback is asynchronous, so this method returns immediately. |
[theMovie play]; |
} |
| |
// When the movie is done, release the controller. |
-(void) myMovieFinishedCallback: (NSNotification*) aNotification |
{ |
MPMoviePlayerController* theMovie = [aNotification object]; |
| |
[[NSNotificationCenter defaultCenter] |
removeObserver: self |
name: MPMoviePlayerPlaybackDidFinishNotification |
object: theMovie]; |
| |
// Release the movie instance created in playMovieAtURL: |
[theMovie release]; |
} |
https://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MediaPlayer_Framework/_index.html#//apple_ref/doc/uid/TP40006952
| Framework |
/System/Library/Frameworks/MediaPlayer.framework
|
| Header file directories |
/System/Library/Frameworks/MediaPlayer.framework/Headers
|
- Class References
- MPMediaEntity
- MPMediaItem
- MPMediaItemArtwork
- MPMediaItemCollection
- MPMediaLibrary
- MPMediaPickerController
- MPMediaPlaylist
- MPMediaPredicate
- MPMediaPropertyPredicate
- MPMediaQuery
- MPMediaQuerySection
- MPMovieAccessLog
- MPMovieAccessLogEvent
- MPMovieErrorLog
- MPMovieErrorLogEvent
- MPMoviePlayerController
- MPMoviePlayerViewController
- MPMusicPlayerController
- MPNowPlayingInfoCenter
- MPTimedMetadata
- MPVolumeView
- UIViewController MediaPlayer Additions
- Protocol References
- MPMediaPickerControllerDelegate
- MPMediaPlayback
- Other References
- Media Player Functions

被折叠的 条评论
为什么被折叠?



