1
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import { AVCaptureSession, AVAssetExportPresetHighestQuality, AVCaptureDevice, AVMediaType, AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureDeviceInput, AVCaptureInput, AVCaptureVideoDataOutput, AVCaptureConnection, AVCaptureVideoPreviewLayer, AVLayerVideoGravity, AVCaptureVideoOrientation, AVCaptureMovieFileOutput, AVCaptureFileOutputRecordingDelegate, AVCaptureOutput, AVCaptureFileOutput, AVAsset, AVAssetExportSession, AVFileType } from 'AVFoundation';
|
||||
import { PHPhotoLibrary, PHAuthorizationStatus } from 'Photos';
|
||||
import { CMSampleBuffer, CMSampleBufferGetFormatDescription, CMFormatDescription, CMVideoFormatDescriptionGetDimensions, CMSampleBufferGetImageBuffer } from 'CoreMedia';
|
||||
import { DispatchQueue } from "Dispatch"
|
||||
import { UIView, UIImage, UISaveVideoAtPathToSavedPhotosAlbum, UIImageWriteToSavedPhotosAlbum, UIApplication, UIImageView, UILabel, UIViewController, UIFontDescriptor, UIFont, NSTextAlignment, UITapGestureRecognizer, UIAlertController, UIGraphicsImageRenderer, UIGraphicsRendererContext, UIBezierPath, CameraDevice, UIImagePickerController } from 'UIKit';
|
||||
import { CGRect, CGFloat, CGPoint, CGAffineTransform, CGSize } from 'CoreFoundation';
|
||||
|
||||
import { NotificationCenter, NSNotification, Notification, FileManager, Data, URL, NSError } from 'Foundation';
|
||||
import { Selector } from 'ObjectiveC';
|
||||
import { Alignment } from 'ARKit';
|
||||
import { CIImage, CIContext } from 'CoreImage';
|
||||
import { CGPath } from 'CoreGraphics';
|
||||
|
||||
import { xCamreaUOpts } from '../interface.uts';
|
||||
import { xCamrea } from './libs/camrea.uts';
|
||||
|
||||
const camera = new xCamrea();
|
||||
export class xCamreaU {
|
||||
$element : UniNativeViewElement;
|
||||
targetView : UIView = new UIView();
|
||||
config : xCamreaUOpts;
|
||||
|
||||
constructor(element : UniNativeViewElement, opts : xCamreaUOpts) {
|
||||
this.config = opts;
|
||||
this.$element = element;
|
||||
this.$element.bindIOSView(this.targetView);
|
||||
camera.setView(this.targetView)
|
||||
}
|
||||
getIsOpeningCameraing():boolean{
|
||||
return camera.getIsOpeningCameraing()
|
||||
}
|
||||
setCameraDir(dir:string){
|
||||
camera.setCameraDir(dir)
|
||||
}
|
||||
setFlash(flash:boolean){
|
||||
camera.setFlash(flash)
|
||||
}
|
||||
openCamrea(){
|
||||
camera.openCamrea()
|
||||
}
|
||||
|
||||
takePhoto(call:(path:string)=>void){
|
||||
camera.takePhoto((path:string)=>{
|
||||
call(path)
|
||||
},false)
|
||||
}
|
||||
start(call:(path:string)=>void) {
|
||||
camera.startRecoderVideo(call)
|
||||
}
|
||||
pause(){
|
||||
camera.pauseRecoderVideo()
|
||||
}
|
||||
|
||||
stop(){
|
||||
camera.stopRecoderVideo()
|
||||
}
|
||||
|
||||
/** 关闭相机 */
|
||||
close() {
|
||||
camera.closeCamrea()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 检查权限
|
||||
export function checkPermissions():Promise<boolean> {
|
||||
return new Promise((res, rej) => {
|
||||
PHPhotoLibrary.requestAuthorization((isok : PHAuthorizationStatus) => {
|
||||
// 拒绝了相册选取权限。
|
||||
if (isok != PHAuthorizationStatus.authorized) {
|
||||
rej(false)
|
||||
return;
|
||||
}
|
||||
AVCaptureDevice.requestAccess(for = AVMediaType.video, completionHandler = (isok2 : boolean) => {
|
||||
if (!isok2) {
|
||||
rej(false)
|
||||
return;
|
||||
}
|
||||
|
||||
AVCaptureDevice.requestAccess(for = AVMediaType.audio, completionHandler = (isok3 : boolean) => {
|
||||
if (!isok3) {
|
||||
rej(false)
|
||||
return;
|
||||
}
|
||||
res(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user