mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
ios shared works on ipad
This commit is contained in:
@@ -28,6 +28,7 @@ import {MAT_DATE_LOCALE} from '@angular/material/core';
|
||||
import { Network } from '@ionic-native/network/ngx';
|
||||
import { MultipleDocumentsPicker } from '@awesome-cordova-plugins/multiple-document-picker/ngx';
|
||||
import { DocumentViewer } from '@awesome-cordova-plugins/document-viewer/ngx';
|
||||
import { FFMpeg } from '@awesome-cordova-plugins/ffmpeg/ngx';
|
||||
|
||||
|
||||
|
||||
@@ -213,6 +214,7 @@ import { FirebaseX } from '@ionic-native/firebase-x/ngx'; */
|
||||
NgxExtendedPdfViewerModule,
|
||||
FileOpener,
|
||||
DocumentViewer,
|
||||
FFMpeg,
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: LoggingInterceptorService, multi: true },
|
||||
tokenInterceptor
|
||||
|
||||
|
||||
@@ -104,7 +104,8 @@ export class HomePage implements OnInit {
|
||||
public ActiveTabService: ActiveTabService,
|
||||
private RoleIdService: RoleIdService,
|
||||
private modalController: ModalController,
|
||||
private zone: NgZone
|
||||
private zone: NgZone,
|
||||
public alertController: AlertController,
|
||||
|
||||
// private ChunkService: ChunkService,
|
||||
// private StreamService: StreamService
|
||||
@@ -165,7 +166,11 @@ export class HomePage implements OnInit {
|
||||
}
|
||||
if (result.url) {
|
||||
window["sharedContent"] = result;
|
||||
this.zone.run(() => this.router.navigateByUrl("/home/publications"));
|
||||
this.zone.run(() => this.router.navigateByUrl("/home/publications")).then(() => {
|
||||
this.alertMessageSharerContent();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}).catch(err => console.error(err));
|
||||
|
||||
@@ -410,4 +415,20 @@ export class HomePage implements OnInit {
|
||||
})
|
||||
}
|
||||
|
||||
alertMessageSharerContent() {
|
||||
this.alertController .create({
|
||||
header: 'Selecione uma acção para criar a publicação',
|
||||
message: '',
|
||||
buttons: [
|
||||
{
|
||||
text: 'Ok',
|
||||
handler: () => {
|
||||
}
|
||||
}
|
||||
]
|
||||
}).then(res => {
|
||||
res.present();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import { checkFileTypeService } from 'src/app/services/checkFileType.service';
|
||||
import { FileValidatorService } from "src/app/services/file/file-validator.service"
|
||||
import { App } from '@capacitor/app';
|
||||
import { Router } from '@angular/router';
|
||||
import { VideoconvertService } from 'src/app/services/videoconvert.service'
|
||||
|
||||
|
||||
const config = {
|
||||
@@ -139,6 +140,7 @@ export class NewPublicationPage implements OnInit {
|
||||
public checkFileType: checkFileTypeService,
|
||||
private FileValidatorService: FileValidatorService,
|
||||
private router: Router,
|
||||
private videoconvertService: VideoconvertService
|
||||
) {
|
||||
|
||||
this.publicationType = this.navParams.get('publicationType');
|
||||
@@ -255,46 +257,9 @@ export class NewPublicationPage implements OnInit {
|
||||
|
||||
try {
|
||||
if (this.platform.is('ios')) {
|
||||
const result = await Filesystem.writeFile({
|
||||
path: 'video.mov',
|
||||
data: element.fullPath,
|
||||
directory: FilesystemDirectory.Data,
|
||||
encoding: FilesystemEncoding.UTF8
|
||||
})
|
||||
console.log('Wrote file', result);
|
||||
|
||||
Filesystem.readFile({ path: result.uri })
|
||||
|
||||
.then(async (content) => {
|
||||
console.log(content.data)
|
||||
this.filecontent = true;
|
||||
let fileObject = {
|
||||
FileBase64: 'data:video/mp4;base64,' + content.data,
|
||||
FileExtension: 'mp4',
|
||||
OriginalFileName: 'video'
|
||||
}
|
||||
this.seletedContent.push(fileObject)
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
this.recordevideoIos(element.fullPath)
|
||||
} else {
|
||||
const savedFile = await Filesystem.copy({
|
||||
from: Capacitor.convertFileSrc(element.fullPath), // directory prop removed, Capacitor parses filename for us
|
||||
to: "video.mp4",
|
||||
toDirectory: FilesystemDirectory.Data
|
||||
});
|
||||
console.log(savedFile.uri)
|
||||
Filesystem.readFile({ path: savedFile.uri })
|
||||
|
||||
.then(async (content) => {
|
||||
this.filecontent = true;
|
||||
let fileObject = {
|
||||
FileBase64: 'data:video/mp4;base64,' + content.data,
|
||||
FileExtension: 'mp4',
|
||||
OriginalFileName: 'video'
|
||||
}
|
||||
this.seletedContent.push(fileObject)
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
@@ -842,5 +807,58 @@ export class NewPublicationPage implements OnInit {
|
||||
App.exitApp()
|
||||
}
|
||||
|
||||
async recordevideoIos(fullPath) {
|
||||
try {
|
||||
const directory = await Filesystem.getUri({
|
||||
directory: Directory.Cache,
|
||||
path: '',
|
||||
});
|
||||
|
||||
this.videoconvertService.convertVideo(fullPath,directory.uri,'mp4');
|
||||
|
||||
Filesystem.readFile({ path: `${directory.uri}output.mp4`})
|
||||
|
||||
.then(async (content) => {
|
||||
console.log(content.data)
|
||||
this.filecontent = true;
|
||||
let fileObject = {
|
||||
FileBase64: 'data:video/mp4;base64,' + content.data,
|
||||
FileExtension: 'mp4',
|
||||
OriginalFileName: 'video'
|
||||
}
|
||||
this.seletedContent.push(fileObject)
|
||||
})
|
||||
.catch((erro) => console.error('read converted video erro ', erro));
|
||||
} catch (error) {
|
||||
console.log('record video ios erro, ', error)
|
||||
}
|
||||
}
|
||||
|
||||
async recordVideoAndroid(fullPath) {
|
||||
try {
|
||||
const savedFile = await Filesystem.copy({
|
||||
from: Capacitor.convertFileSrc(fullPath),
|
||||
to: "video.mp4",
|
||||
toDirectory: FilesystemDirectory.Data
|
||||
});
|
||||
console.log(savedFile.uri)
|
||||
Filesystem.readFile({ path: savedFile.uri })
|
||||
|
||||
.then(async (content) => {
|
||||
this.filecontent = true;
|
||||
let fileObject = {
|
||||
FileBase64: 'data:video/mp4;base64,' + content.data,
|
||||
FileExtension: 'mp4',
|
||||
OriginalFileName: 'video'
|
||||
}
|
||||
this.seletedContent.push(fileObject)
|
||||
})
|
||||
.catch((error) => console.error('reade converted video erro ',error));
|
||||
|
||||
} catch (error) {
|
||||
console.log('record video android erro ', error)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router, NavigationEnd } from '@angular/router';
|
||||
import { ModalController, NavParams } from '@ionic/angular';
|
||||
import { AlertController, ModalController, NavParams } from '@ionic/angular';
|
||||
import { PublicationFolder } from 'src/app/models/publicationfolder';
|
||||
import { PublicationsService } from 'src/app/services/publications.service';
|
||||
import { NewActionPage } from './new-action/new-action.page';
|
||||
@@ -78,6 +78,7 @@ export class PublicationsPage implements OnInit {
|
||||
private StreamService:StreamService,
|
||||
private http: HttpClient,
|
||||
|
||||
|
||||
) {
|
||||
this.months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
|
||||
this.days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
|
||||
|
||||
@@ -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/mov', 'video/*']; // Add more if needed
|
||||
'video/mp4', 'video/webm', 'video/mpg', 'video/mpeg', 'video/ogg','video/quicktime', 'video/*']; // Add more if needed
|
||||
|
||||
// Check if it's an image
|
||||
if (imageExtensions.includes(lowerCaseType)) {
|
||||
|
||||
@@ -2,14 +2,17 @@ import { Filesystem } from '@capacitor/filesystem';
|
||||
import { SendIntent } from "send-intent";
|
||||
import { Router } from '@angular/router';
|
||||
import { CallbackScheduler } from './callbackScheduler';
|
||||
import { AlertController, Platform } from '@ionic/angular';
|
||||
|
||||
export class SendIntentService {
|
||||
|
||||
Router!: Router
|
||||
|
||||
callbackScheduler = new CallbackScheduler()
|
||||
alertController = new AlertController()
|
||||
|
||||
constructor() {
|
||||
constructor(
|
||||
) {
|
||||
|
||||
SendIntent.checkSendIntentReceived().then((result: any) => {
|
||||
// logger
|
||||
@@ -36,11 +39,32 @@ export class SendIntentService {
|
||||
|
||||
|
||||
private onReceive = this.callbackScheduler.function<any>((result)=> {
|
||||
this.Router.navigateByUrl("/home/publications");
|
||||
this.Router.navigateByUrl("/home/publications").then(() => {
|
||||
if(Platform.prototype.is('ios')) {
|
||||
this.alertIos();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
window["sharedContent"] = result;
|
||||
})
|
||||
|
||||
private alertIos() {
|
||||
this.alertController .create({
|
||||
header: 'Selecione uma acção para criar a publicação',
|
||||
message: '',
|
||||
buttons: [
|
||||
{
|
||||
text: 'Ok',
|
||||
handler: () => {
|
||||
}
|
||||
}
|
||||
]
|
||||
}).then(res => {
|
||||
res.present();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const sendIntent = new SendIntentService()
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { VideoconvertService } from './videoconvert.service';
|
||||
|
||||
describe('VideoconvertService', () => {
|
||||
let service: VideoconvertService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(VideoconvertService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { FFMpeg } from '@awesome-cordova-plugins/ffmpeg/ngx';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class VideoconvertService {
|
||||
|
||||
constructor(
|
||||
private ffmpeg: FFMpeg
|
||||
) { }
|
||||
|
||||
async convertVideo(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}`);
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,11 @@ import { SocketConnectionMCRService } from "src/app/services/socket-connection-m
|
||||
import { CMAPIService } from '../../repository/CMAPI/cmapi.service';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { CaptureImageOptions, MediaCapture } from '@awesome-cordova-plugins/media-capture/ngx';
|
||||
import { Filesystem, FilesystemDirectory } from '@capacitor/filesystem';
|
||||
import { Directory, Filesystem, FilesystemDirectory } from '@capacitor/filesystem';
|
||||
import { Platform } from '@ionic/angular';
|
||||
import { PublicationAttachmentEntity, PublicationFormMV } from '../upload/upload-streaming.service';
|
||||
import { PublicationFormMVService } from "src/app/shared/publication/upload/publication-form-mv.service"
|
||||
import { VideoconvertService } from 'src/app/services/videoconvert.service';
|
||||
|
||||
enum ActionType {
|
||||
newRapid = "1",
|
||||
@@ -86,6 +87,7 @@ export class NewPublicationPage implements OnInit {
|
||||
private MiddlewareServiceService: MiddlewareServiceService,
|
||||
private LakefsRepositoryService: LakefsRepositoryService,
|
||||
private SocketConnectionMCRService: SocketConnectionMCRService,
|
||||
private videoconvertService: VideoconvertService
|
||||
) {
|
||||
this.publicationTitle = 'Nova Publicação';
|
||||
}
|
||||
@@ -727,29 +729,11 @@ export class NewPublicationPage implements OnInit {
|
||||
data.forEach(async element => {
|
||||
this.filesSizeSum = this.filesSizeSum + element.size
|
||||
if (this.fileSizeToMB(this.filesSizeSum) <= 20) {
|
||||
const savedFile = await Filesystem.copy({
|
||||
from: element.fullPath, // directory prop removed, Capacitor parses filename for us
|
||||
to: "video.mp4",
|
||||
toDirectory: FilesystemDirectory.Data
|
||||
});
|
||||
console.log(savedFile.uri)
|
||||
Filesystem.readFile({ path: savedFile.uri })
|
||||
|
||||
.then(async (content) => {
|
||||
this.filecontent = true;
|
||||
console.log('', content)
|
||||
let fileObject = new PublicationAttachmentEntity({
|
||||
base64: content.data,
|
||||
extension: 'mp4',
|
||||
OriginalFileName: 'record',
|
||||
FileType: 'video'
|
||||
|
||||
}
|
||||
)
|
||||
this.publicationFormMV.form.Files.push(fileObject)
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
if(this.platform.is('ios'))
|
||||
this.recordevideoIos(element.fullPath)
|
||||
} else {
|
||||
this.recordVideoPc(element.fullPath)
|
||||
|
||||
if (this.publicationFormMV.form.Files.length === 0)
|
||||
this.filesSizeSum = 0
|
||||
|
||||
@@ -771,6 +755,65 @@ export class NewPublicationPage implements OnInit {
|
||||
if (this.platform.is('desktop'))
|
||||
return true;
|
||||
}
|
||||
|
||||
async recordevideoIos(fullPath) {
|
||||
try {
|
||||
const directory = await Filesystem.getUri({
|
||||
directory: Directory.Cache,
|
||||
path: '',
|
||||
});
|
||||
|
||||
this.videoconvertService.convertVideo(fullPath,directory.uri,'mp4');
|
||||
|
||||
Filesystem.readFile({ path: `${directory.uri}output.mp4`})
|
||||
|
||||
.then(async (content) => {
|
||||
this.filecontent = true;
|
||||
console.log('', content)
|
||||
let fileObject = new PublicationAttachmentEntity({
|
||||
base64: content.data,
|
||||
extension: 'mp4',
|
||||
OriginalFileName: 'record',
|
||||
FileType: 'video'
|
||||
|
||||
}
|
||||
)
|
||||
this.publicationFormMV.form.Files.push(fileObject)
|
||||
})
|
||||
.catch((erro) => console.error('read converted video erro ', erro));
|
||||
} catch (error) {
|
||||
console.log('record video ios erro, ', error)
|
||||
}
|
||||
}
|
||||
|
||||
async recordVideoPc(fullPath) {
|
||||
try {
|
||||
const savedFile = await Filesystem.copy({
|
||||
from: fullPath, // directory prop removed, Capacitor parses filename for us
|
||||
to: "video.mp4",
|
||||
toDirectory: FilesystemDirectory.Data
|
||||
});
|
||||
console.log(savedFile.uri)
|
||||
Filesystem.readFile({ path: savedFile.uri })
|
||||
|
||||
.then(async (content) => {
|
||||
this.filecontent = true;
|
||||
console.log('', content)
|
||||
let fileObject = new PublicationAttachmentEntity({
|
||||
base64: content.data,
|
||||
extension: 'mp4',
|
||||
OriginalFileName: 'record',
|
||||
FileType: 'video'
|
||||
|
||||
}
|
||||
)
|
||||
this.publicationFormMV.form.Files.push(fileObject)
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user