調(diào)用系統(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];
//通過(guò)AVPlayerItem創(chuàng)建AVPlayer
self.player = [[AVPlayer alloc]initWithPlayerItem:item];
//設(shè)置AVPlayerViewController內(nèi)部的AVPlayer為剛創(chuàng)建的AVPlayer
self.playerView.player = self.player;
//關(guān)閉AVPlayerViewController內(nèi)部的約束
self.playerView.view.translatesAutoresizingMaskIntoConstraints = YES;
[self presentViewController:self.playerView animated:YES completion:nil];
播放一段文本
將文本當(dāng)做聲音播放(默認(rèn)播放英文)
AVSpeechSynthesizer *syn = [[AVSpeechSynthesizeralloc]init];
AVSpeechUtterance *utterance = [[AVSpeechUtterancealloc]initWithString:@“hello world"];
[syn speakUtterance:utterance];
AVAduioSession 應(yīng)用程序與音頻會(huì)話交互的接口
session = [AVAudioSession sharedInstance]//獲取session單利
[session setCateGory:AVAudioSessionCategoryPlayback error:&error];// 設(shè)置會(huì)話模式
[session setActive:YES error:&error];//激活設(shè)置的模式
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;//播放速率
音頻會(huì)話的中斷通知
//添加中斷通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
權(quán)限判斷
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
{
//無(wú)權(quán)限
}
#import <AssetsLibrary/AssetsLibrary.h>
ALAuthorizationStatus author = [ALAssetsLibraryauthorization Status];
if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){
//無(wú)權(quán)限
}
typedef enum {
kCLAuthorizationStatusNotDetermined = 0, // 用戶(hù)尚未做出選擇這個(gè)應(yīng)用程序的問(wèn)候
kCLAuthorizationStatusRestricted, // 此應(yīng)用程序沒(méi)有被授權(quán)訪問(wèn)的照片數(shù)據(jù)畴蒲∮瓢埃可能是家長(zhǎng)控制權(quán)限
kCLAuthorizationStatusDenied, // 用戶(hù)已經(jīng)明確否認(rèn)了這一照片數(shù)據(jù)的應(yīng)用程序訪問(wèn)
kCLAuthorizationStatusAuthorized // 用戶(hù)已經(jīng)授權(quán)應(yīng)用訪問(wèn)照片數(shù)據(jù)} CLAuthorizationStatus;
}
- 打開(kāi)應(yīng)用程序權(quán)限設(shè)置
[[UIApplication sharedApplication]openURL:[NSURLURLWithString:UIApplicationOpenSettingsURLString]];
開(kāi)關(guān)手電筒
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch]) {
[device lockForConfiguration:nil];
if (open) {
[device setTorchMode:AVCaptureTorchModeOn];
} else {
[device setTorchMode:AVCaptureTorchModeOff];
}
[device unlockForConfiguration];
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者