mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { CaptureImageOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx';
|
|
import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera';
|
|
import { File } from "@awesome-cordova-plugins/file/ngx"
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class CameraService {
|
|
|
|
constructor(
|
|
private mediaCapture: MediaCapture,
|
|
private file: File) { }
|
|
|
|
|
|
async takePicture() {
|
|
|
|
return new Promise<Photo>(async (resolve, reject)=>{
|
|
|
|
|
|
|
|
const image = await Camera.getPhoto({
|
|
quality: 50,
|
|
allowEditing: false,
|
|
resultType: CameraResultType.Uri,
|
|
source: CameraSource.Camera // Camera, Photos or Prompt!
|
|
});
|
|
|
|
if (image) {
|
|
resolve(image)
|
|
|
|
} else {
|
|
reject('Error saving image')
|
|
}
|
|
|
|
//this.capturedImage = this.capturedImage;
|
|
})
|
|
|
|
}
|
|
|
|
async startRecording() {
|
|
try {
|
|
let options: CaptureImageOptions = { limit: 1}
|
|
|
|
const data: MediaFile[] = (await this.mediaCapture.captureVideo(options) as any )
|
|
const video = data[0]
|
|
|
|
let dir = video.fullPath.split("/")
|
|
dir.pop()
|
|
let fromDir = dir.join("/")
|
|
let toDir = this.file.dataDirectory
|
|
|
|
const response = await this.file.copyFile(fromDir, video.name, toDir, video.name )
|
|
console.log({response})
|
|
|
|
} catch(e) {
|
|
console.log(e)
|
|
}
|
|
}
|
|
|
|
nice() {}
|
|
}
|