add try catch to video.foreach and video.pause

This commit is contained in:
Eudes Inácio
2024-02-05 10:29:42 +01:00
parent a873e192ee
commit d7980908dd
7 changed files with 137 additions and 56 deletions
@@ -31,6 +31,9 @@ import { File } from '@ionic-native/file/ngx';
import { Media } from '@ionic-native/media/ngx';
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';
const config = {
quality: 0.5,
maxWidth: 800,
@@ -133,7 +136,8 @@ export class NewPublicationPage implements OnInit {
public FileService: FileService,
private mediaCapture: MediaCapture,
public checkFileType: checkFileTypeService,
private FileValidatorService: FileValidatorService
private FileValidatorService: FileValidatorService,
private router: Router,
) {
this.publicationType = this.navParams.get('publicationType');
@@ -536,10 +540,11 @@ export class NewPublicationPage implements OnInit {
await this.publications.CreatePublication(this.folderId, this.publication).toPromise();
this.close();
this.httpErrorHandle.httpsSucessMessagge('Criar publicação')
window["sharedContent"] = null;
window["endSharedContent"] = null;
if(window["sharedContent"]) {
this.router.navigate(['/home/publications', this.folderId]);
return
}
this.close();
} catch (error) {
@@ -562,6 +567,10 @@ export class NewPublicationPage implements OnInit {
this.modalController.dismiss(this.publication).then(() => {
this.showLoader = true;
});
if(window["sharedContent"]) {
this.closeApp();
}
}
clear() {
@@ -782,5 +791,9 @@ export class NewPublicationPage implements OnInit {
this.seletedContent.splice(index, 1)
}
closeApp() {
App.exitApp()
}
}
@@ -24,7 +24,7 @@
</div> -->
</div>
<div *ngIf="!intent" class="div-icon">
<div class="div-icon">
<button *ngIf="p.userPermission([p.permissionList.Actions.create])" title="Adicionar nova ação presidencial" class="btn-no-color" (click)="AddPublicationFolder()">
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " slot="icon-only" src='assets/images/icons-add.svg'></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " slot="icon-only" src='assets/images/theme/gov/icons-add.svg'></ion-icon>
@@ -34,12 +34,12 @@
<ion-icon class=" font-45-em" src="assets/images/theme/gov/icon-reload.svg"></ion-icon>
</button>
</div>
<div *ngIf="intent" class="div-icon">
<!-- <div *ngIf="intent" class="div-icon">
<button title="Atualizar" class="btn-no-color" (click)="close()">
<ion-icon class=" font-45-em" src="assets/images/icons-search-close.svg"></ion-icon>
</button>
</div>
</div> -->
</div>
</div>
@@ -349,7 +349,7 @@ export class PublicationsPage implements OnInit {
componentProps: {
publicationType: publicationType,
folderId: folderId,
intent: intent
intent: window["sharedContent"]
},
cssClass: 'new-publication modal modal-desktop',
backdropDismiss: false
@@ -362,8 +362,8 @@ export class PublicationsPage implements OnInit {
}
goToPublicationsList(folderId: string) {
if(this.intent){
this.AddPublication('2',folderId,this.intent)
if(window["sharedContent"]){
this.AddPublication('2',folderId,window["sharedContent"])
return
}
if (window.innerWidth < 701) {
@@ -19,6 +19,7 @@ import { checkFileTypeService } from 'src/app/services/checkFileType.service';
import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service"
import { StopvideoService } from "src/app/services/stopvideo.service"
import { Result } from 'neverthrow';
import { App } from '@capacitor/app';
@Component({
selector: 'app-view-publications',
templateUrl: './view-publications.page.html',
@@ -131,6 +132,7 @@ export class ViewPublicationsPage implements OnInit {
stopVideo() {
var videos = document.querySelectorAll('video');
try {
// Pause each video
videos.forEach(function (video) {
video.pause();
@@ -145,6 +147,9 @@ export class ViewPublicationsPage implements OnInit {
// Do something with each video element
// console.log(video);
});
} catch (error) {
console.log(error)
}
}
ngOnChanges() {
@@ -186,6 +191,10 @@ export class ViewPublicationsPage implements OnInit {
}
goBack() {
if (window["sharedContent"]) {
App.exitApp();
return
}
this.router.navigate(['/home/publications']);
}
+53
View File
@@ -0,0 +1,53 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class ChunksService {
chunkSize: number
private file: File
constructor() {
}
get totalChunks () {
return Math.ceil(this.file.size / this.chunkSize);
}
// Function to read a chunk of the file
readChunk(start: number, end: number): Promise<ArrayBuffer> {
const file = this.file
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
if (reader.result instanceof ArrayBuffer) {
resolve(reader.result);
} else {
reject(new Error("Failed to read chunk"));
}
};
reader.readAsArrayBuffer(file.slice(start, end));
});
}
setFile(file) {
this.file = file
}
async getChunks(i: number,chunkSize: number) {
i--
if(i < this.totalChunks) {
const start = i * chunkSize;
const end = Math.min(start + chunkSize, this.file.size);
const chunk = await this.readChunk(start, end);
return chunk
}
}
}
@@ -370,6 +370,7 @@ export class ViewPublicationsPage implements OnInit {
stopVideo() {
var videos = document.querySelectorAll('video');
try {
// Pause each video
videos.forEach(function (video) {
video.pause();
@@ -384,6 +385,10 @@ export class ViewPublicationsPage implements OnInit {
// Do something with each video element
// console.log(video);
});
} catch (error) {
console.log(error)
}
}
public onScroll(event): void {
+1
View File
@@ -0,0 +1 @@
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><filter id="a" color-interpolation-filters="sRGB" height="1.2568" width="1.2568" x="-.1284" y="-.1284"><feGaussianBlur stdDeviation="1.177"/></filter><g transform="matrix(.65100396 0 0 .65100396 -206.81858 -480.74574)"><path d="m336.1248 747.43738c-6.07513 0-11 4.92487-11 11s4.92487 11 11 11 11-4.92487 11-11-4.92487-11-11-11z" filter="url(#a)" opacity=".2"/><circle cx="336.1248" cy="757.42456" fill="#fff" r="11"/><path d="m331.1248 748.77713c-4.78293 2.76142-6.42168 8.87732-3.66025 13.66025 2.76142 4.78293 8.87732 6.42168 13.66025 3.66025 4.78293-2.76142 6.42168-8.87732 3.66025-13.66025-2.76142-4.78293-8.87732-6.42168-13.66025-3.66025zm1 1.73205c3.5319-2.03915 7.9742-1.07566 10.37408 2.09342l-13.74816 7.9375c-1.54456-3.66289-.15782-7.99178 3.37408-10.03092zm-2.37408 11.76298 13.74816-7.9375c1.54456 3.66289.15782 7.99178-3.37408 10.03092-3.5319 2.03915-7.9742 1.07566-10.37408-2.09342z" fill="#ed1515"/></g></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB