9、AVFoundation

調用系統(tǒng)封裝好的播放界面
//視頻播放的url
    NSURL *playerURL = [NSURL fileURLWithPath:self.datasource[indexPath.row]];
    //初始化
    self.playerView = [[AVPlayerViewController alloc]init];
    //AVPlayerItem 視頻的一些信息  創(chuàng)建AVPlayer使用的
    AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:playerURL];
    //通過AVPlayerItem創(chuàng)建AVPlayer
    self.player = [[AVPlayer alloc]initWithPlayerItem:item];
    //設置AVPlayerViewController內部的AVPlayer為剛創(chuàng)建的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;//循環(huán)
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];
    }
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 發(fā)現 關注 消息 iOS 第三方庫、插件、知名博客總結 作者大灰狼的小綿羊哥哥關注 2017.06.26 09:4...
    肇東周閱讀 12,259評論 4 61
  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現,斷路器,智...
    卡卡羅2017閱讀 134,993評論 19 139
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,595評論 25 708
  • UIImagePickerController確實強大,但是與MPMoviePlayerController類似,...
    Realank閱讀 5,224評論 0 20
  • 一個人最痛苦的是飽受精神折磨,也許肉體的疼痛會通過藥劑緩解,但精神失控卻無能為力。我相信約翰.納什是在用科學的狂熱...
    roseday閱讀 356評論 0 0