9、AVFoundation

调用系统封装好的播放界面
//视频播放的url
    NSURL *playerURL = [NSURL fileURLWithPath:self.datasource[indexPath.row]];
    //初始化
    self.playerView = [[AVPlayerViewController alloc]init];
    //AVPlayerItem 视频的一些信息  创建AVPlayer使用的
    AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:playerURL];
    //通过AVPlayerItem创建AVPlayer
    self.player = [[AVPlayer alloc]initWithPlayerItem:item];
    //设置AVPlayerViewController内部的AVPlayer为刚创建的AVPlayer
    self.playerView.player = self.player;
    //关闭AVPlayerViewController内部的约束
    self.playerView.view.translatesAutoresizingMaskIntoConstraints = YES;
    [self presentViewController:self.playerView animated:YES completion:nil];
播放一段文本
将文本当做声音播放(默认播放英文)
AVSpeechSynthesizer *syn = [[AVSpeechSynthesizeralloc]init];
AVSpeechUtterance *utterance = [[AVSpeechUtterancealloc]initWithString:@“hello world"];
[syn speakUtterance:utterance];
AVAduioSession 应用程序与音频会话交互的接口
session = [AVAudioSession sharedInstance]//获取session单利
[session setCateGory:AVAudioSessionCategoryPlayback error:&error];//     设置会话模式
[session setActive:YES error:&error];//激活设置的模式
AVAudioPlayer 音频播放器属性
self.audioPlayer.numberOfLoops = -1;//循环
self.audioPlayer.volume = self.volumeValue;//音量
self.audioPlayer.pan = self.panValue;//左右声道
self.audioPlayer.enableRate = YES;
self.audioPlayer.rate = 1;//播放速率
音频会话的中断通知
//添加中断通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
权限判断
  • 相机权限判断
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
{
    //无权限
}
  • 相册权限判断
#import <AssetsLibrary/AssetsLibrary.h>
ALAuthorizationStatus author = [ALAssetsLibraryauthorization Status];
    if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){
        //无权限
    }
    typedef enum {
        kCLAuthorizationStatusNotDetermined = 0, // 用户尚未做出选择这个应用程序的问候
        kCLAuthorizationStatusRestricted,        // 此应用程序没有被授权访问的照片数据。可能是家长控制权限
        kCLAuthorizationStatusDenied,            // 用户已经明确否认了这一照片数据的应用程序访问
        kCLAuthorizationStatusAuthorized         // 用户已经授权应用访问照片数据} CLAuthorizationStatus;
    }
  • 打开应用程序权限设置
    [[UIApplication sharedApplication]openURL:[NSURLURLWithString:UIApplicationOpenSettingsURLString]];
开关手电筒
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if ([device hasTorch]) {
        [device lockForConfiguration:nil];
        if (open) {
            [device setTorchMode:AVCaptureTorchModeOn];
        } else {
            [device setTorchMode:AVCaptureTorchModeOff];
        }
        [device unlockForConfiguration];
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,180评论 4 61
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,837评论 18 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,813评论 25 708
  • UIImagePickerController确实强大,但是与MPMoviePlayerController类似,...
    Realank阅读 5,208评论 0 20
  • 一个人最痛苦的是饱受精神折磨,也许肉体的疼痛会通过药剂缓解,但精神失控却无能为力。我相信约翰.纳什是在用科学的狂热...
    roseday阅读 346评论 0 0