調用系統(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ā)布平臺,僅提供信息存儲服務。