一:assetslibrary
读取photo 和video
1:add AssetsLibrary
2:#import <AssetsLibrary/AssetsLibrary.h>
3:
-(IBAction) getStats { __block int numberOfGroups = 0; __block int numberOfAssets = 0; // Create the object to represent the library ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init]; // What kind of groups are you interested in? NSUInteger groupTypes = ALAssetsGroupAll; // Create the block to enumerate through the groups ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) { // this block will be called for every group, and ONCE MORE! // so first, test if there's a real group being passed in: if (group) { // add to the totals numberOfGroups++; numberOfAssets += group.numberOfAssets; // output some info about the group NSLog(@"The name of the group is, %@", [group valueForProperty:ALAssetsGroupPropertyName]); } else { // the group object is nil, must mean we're done enumerating! // create an output message. NSString *message = [NSString stringWithFormat:@"There are %d groups with %d total assets.", numberOfGroups,numberOfAssets]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Asset Stats!" message:message delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil]; [alert show]; [alert release]; } }; // create the failure block ALAssetsLibraryAccessFailureBlock failBlock = ^(NSError *error) { NSLog(@"Error:%@", [error localizedDescription]); }; // now enumerate through the groups, using the created blocks [assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failBlock]; [assetsLibrary release]; }
二:在你的app 中播放视频
1:add MediaPlayer
2:#import <MediaPlayer/MediaPlayer.h>
3:
-(IBAction) buttonTapped: (id) sender { NSString *path = [[NSBundle mainBundle] pathForResource:@"water" ofType:@"m4v"]; player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlaying:) name:MPMoviePlayerPlaybackDidFinishNotification object:[player moviePlayer]]; [self presentMoviePlayerViewControllerAnimated:player]; }
-(void) movieFinishedPlaying: (NSNotification *) note { [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:[player moviePlayer]]; [player release]; }