一: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];
}
分享到:
相关推荐
AssetsLibrary同样可以获取照片和视频,但其API相比PhotoKit略显复杂,且不支持某些新特性,如Live Photos和HEIC格式。 3. **图片选择与预览**:项目中,用户可以选择多张图片进行预览,这涉及到图片的选取逻辑和UI...
- 在iOS端,使用Photos框架(在iOS 6及以上版本中替代了旧的AssetsLibrary框架)。导入Photos框架并使用PHPhotoLibrary、PHAsset和PHImageManager类。 - 实现请求用户授权的代码,使用PHPhotoLibrary....
总的来说,`LWGPhotos`是一个强大的工具,可以帮助iOS开发者高效地管理和获取用户设备上的图片,无论是针对较新的还是较旧的iOS系统版本,都能提供稳定的性能和内存优化。通过深入理解和正确使用这个库,开发者可以...
下面将逐一介绍这些框架,包括它们的主要用途、版本信息以及所包含的关键API或特性。 ### 1. Accelerate.framework - **版本**: 4.0 - **主要功能**: 提供了高性能计算库,如`cblas`(用于向量和矩阵操作)与`vDSP`...
5. **Swift语言特性**:作为iOS开发的主要语言,Swift的特性如闭包、泛型、协议扩展等可能在源码中得到体现,帮助开发者更好地处理数据和事件。 6. **GCD(Grand Central Dispatch)**:在处理异步任务和多线程时,...
作者alienjun,源码AJPhotoPicker,用于代替系统的图片选择器的... 特性 基于AssetsLibrary、UICollectionView、Masonry。 支持 视频、图片选择。 支持多选、滑动多选、预览。 使用方式简单,便于定制。
PhotoKit是iOS 8之后推出的新框架,提供了更强大的媒体管理和编辑功能;而AssetsLibrary则在较早的iOS版本中广泛使用。此项目根据设备系统版本的不同,灵活地选择了适合的框架来实现图片和视频的选取。 1. **...
Swift 2.0是苹果在2015年推出的一个重要更新,引入了错误处理(Error Handling)、泛型改进、类型推断增强以及`where`子句等新特性。其中,错误处理通过`try`、`catch`和`throw`关键字使得异常处理更加结构化,提高...