From 8e27bd534d3a0b4706489788012be95b50dccb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Sat, 2 Mar 2024 16:46:28 +0100 Subject: [PATCH] load video formated --- .../new-publication/new-publication.page.html | 2 +- .../new-publication/new-publication.page.ts | 65 +++++++++++-------- src/app/services/checkFileType.service.ts | 2 +- src/app/services/videoconvert.service.ts | 8 +++ 4 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/app/pages/publications/new-publication/new-publication.page.html b/src/app/pages/publications/new-publication/new-publication.page.html index 4ea5b0adc..a091392c3 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.html +++ b/src/app/pages/publications/new-publication/new-publication.page.html @@ -44,7 +44,7 @@ (click)="imageSize(capturedImage)" style="height: 69px;"> diff --git a/src/app/pages/publications/new-publication/new-publication.page.ts b/src/app/pages/publications/new-publication/new-publication.page.ts index f6159a89e..a31feaed8 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -250,8 +250,6 @@ export class NewPublicationPage implements OnInit { this.video = data[0]; console.log('video record', data) data.forEach(async element => { - Capacitor.convertFileSrc(element.fullPath); - console.log('convert url', (Capacitor.convertFileSrc(element.fullPath))); this.filesSizeSum = this.filesSizeSum + element.size if (this.fileSizeToMB(this.filesSizeSum) <= 20) { @@ -286,7 +284,7 @@ export class NewPublicationPage implements OnInit { multiple: true, }); console.log(result.files) - result.files.forEach(element => { + result.files.forEach(async element => { this.filesSizeSum = this.filesSizeSum + element.size if (this.fileSizeToMB(this.filesSizeSum) <= 20) { @@ -296,30 +294,13 @@ export class NewPublicationPage implements OnInit { console.log('pass type verification ', resultUrl) try { - Filesystem.readFile({ path: resultUrl }) - .then(async (content) => { - console.log(result) - console.log(content) - this.filecontent = true; - let fileObject; - if (this.removeTextBeforeSlash(element.mimeType, '/') == "mp4") { - fileObject = { - FileBase64: 'data:video/mp4;base64,' + content.data, - FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), - OriginalFileName: 'video' - } - } else { - fileObject = { - FileBase64: content.data, - FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), - OriginalFileName: 'image' - } - } + if(this.platform.is('ios')) { + this.recordevideoIos(resultUrl) + } else { + this.loadVideoAndroid(resultUrl,element) + } - this.seletedContent.push(fileObject) - }) - .catch((err) => console.error(err)); } catch (error) { console.log('upload video error: ', error) } @@ -845,9 +826,10 @@ export class NewPublicationPage implements OnInit { } async recordVideoAndroid(fullPath) { + try { const savedFile = await Filesystem.copy({ - from: Capacitor.convertFileSrc(fullPath), + from: fullPath, to: "video.mp4", toDirectory: FilesystemDirectory.Data }); @@ -870,5 +852,36 @@ export class NewPublicationPage implements OnInit { } } + loadVideoIso() { + + } + + loadVideoAndroid(resultUrl,element) { + Filesystem.readFile({ path: resultUrl }) + + .then(async (content) => { + console.log(content) + this.filecontent = true; + let fileObject; + if (this.removeTextBeforeSlash(element.mimeType, '/') == "mp4") { + fileObject = { + FileBase64: 'data:video/mp4;base64,' + content.data, + FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), + OriginalFileName: 'video' + } + } else { + fileObject = { + FileBase64: content.data, + FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), + OriginalFileName: 'image' + } + } + + this.seletedContent.push(fileObject) + }) + .catch((err) => console.error(err)); + + } + } diff --git a/src/app/services/checkFileType.service.ts b/src/app/services/checkFileType.service.ts index a8038130c..e0168d542 100644 --- a/src/app/services/checkFileType.service.ts +++ b/src/app/services/checkFileType.service.ts @@ -18,7 +18,7 @@ export class checkFileTypeService { const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp','tiff','tif', 'image/jpg', 'image/jpeg', 'image/png', 'image/gif', 'image/bmp','image/tiff','image/tif', 'image/*']; // Add more if needed const videoExtensions = ['mp4', 'webm', 'mpg', 'mpeg', 'ogg', - 'video/mp4', 'video/webm', 'video/mpg', 'video/mpeg', 'video/ogg','video/quicktime', 'video/*']; // Add more if needed + 'video/mp4', 'video/webm', 'video/mpg', 'video/mpeg', 'video/ogg','video/quicktime','MOV','mov', 'video/*']; // Add more if needed // Check if it's an image if (imageExtensions.includes(lowerCaseType)) { diff --git a/src/app/services/videoconvert.service.ts b/src/app/services/videoconvert.service.ts index d4ef617ae..e15a78cb9 100644 --- a/src/app/services/videoconvert.service.ts +++ b/src/app/services/videoconvert.service.ts @@ -17,4 +17,12 @@ export class VideoconvertService { console.log('Convert returns ', `${outputPath}output.${formart}`); } + + async convertVideoAndroid(inputPath, outputPath, formart) { + const ffmpegCommand = `-i "${inputPath}" -c:v copy -c:a aac -strict experimental "${outputPath}/output.${formart}"`; + + const result = await this.ffmpeg.exec(ffmpegCommand) + + console.log('Convert returns ', `${outputPath}output.${formart}`); + } }