码迷,mamicode.com
首页 > 其他好文 > 详细

音频和视频

时间:2015-08-18 11:54:58      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

1.系统相册和拍照

//有系统预置的多媒体参数
#import <MobileCoreServices/MobileCoreServices.h>

UIImagePickerController 拍照和获取系统相册
判断是否支持
BOOL ret = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    //设置资源类型
    imagePicker.sourceType = type;
    //设置代理
    imagePicker.delegate = self;
    //是否允许对相册 等做后续处理
    imagePicker.allowsEditing = YES;
    [self presentViewController:imagePicker animated:YES completion:^{
        
    }];



#pragma mark - UIImagePickerControllerDelegate
//点击picker上的cancel按钮时,触发的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    NSLog(@"cancel!!");
    //实现picker的dismiss
    [picker dismissViewControllerAnimated:YES completion:^{
    }];
}


//点击choose按钮触发的方法
//info 带有选中资源的信息
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    
    //判断选中的资源的类型
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    //kUTTypeImage 系统预置的图片资源类型
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        //证明取出来的是图片
        //通过字典获取选中的图片
        UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
        //从相机中取出来的图片占的空间:(1M-2M)左右,需要对图片进行压缩处理,然后在进行后续操作
        //将原图压缩成50*50的尺寸
        UIImage *smallImage = [[ImageTool shareTool] resizeImageToSize:CGSizeMake(50,50) sizeOfImage:image];
        self.view.backgroundColor = [UIColor colorWithPatternImage:smallImage];
    }
    [picker dismissViewControllerAnimated:YES completion:^{
   
}];
}


2.视频
MPMoviePlayerViewController
@"http://hot.vrs.sohu.com/ipad1407291_4596271359934_4618512.m3u8"

//创建一个带有视频播放器的控制器
        _playController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
           _playController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
        //通过模态化的方式呈现
        [self presentViewController:_playController animated:YES completion:^{
      
     
        }];


3.音频
AVAudioPlayer协议方法

#pragma mark - AVAudioPlayerDelegate
//当成功播放完成一首歌后,调用此方法
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
    NSLog(@"播放结束");
}

音频和视频

标签:

原文地址:http://blog.csdn.net/shuju345/article/details/47749295

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!