I have build a uploading Video process in my ionic 5 Angular 12 project. The process works fine, the video is uploading and show a corrupted video file as in the photo i attached.
I want to make a preview of the video that the user has uploaded, but the video url seems to be broker and doesn't show the file as i've shown the attached screenshot.
here is my code
html BUTTON TO START THE UPLADING <ion-fab-button color="danger" (click)="chooseVideo()"
HTML5 VIDEO TAG TO SHOW THE UPLOADED VIDEO
<video webkit-playsinline="true" playsinline="true" class="cover-video" controls id="video" (click)="toggleVideo()"
webkit-playsinline #videoPlayer preload="auto">
<source [src]="video_url" [type]="'video/webm'" *ngIf="checkExtension(video_url,'webm')">
<source [src]="video_url" [type]="'video/mp4'" *ngIf="checkExtension(video_url,'mp4')">
<source [src]="video_url" [type]="'video/ogg'" *ngIf="checkExtension(video_url,'ogg')">
</video>
.ts
video_url: string = '';
async chooseVideo() {
const actionSheet = await this.actionSheetCtrl.create({
header: this.translation.select_video_source,
cssClass: 'actionSheetButton',
buttons: [
{
text: this.translation.Use_Camera,
cssClass: 'uploadVideoButton',
handler: () => {
this.captureVideo();
}
},
{
text: this.translation.Cancel,
role: 'cancel'
}
]
});
actionSheet.present();
}
checkExtension(file: string, type: string) {
return this.userData.getFileExtension(file) === type;
}
FUNCTION TO CAPTURE VIDEO FROM CAMERA
captureVideo() {
const options: CaptureVideoOptions = {
limit: 1,
duration: 30
}
this.mediaCapture.captureVideo(options).then((res: MediaFile[]) => {
let capturedFile = res[0];
this.video_url = capturedFile.fullPath;
}, (err: CaptureError) => console.error(err));
}
function to play video_url
playVideo() {
let options: StreamingVideoOptions = {
successCallback: () => { },
errorCallback: (e) => { console.log('Error streaming') },
orientation: 'landscape'
};
this.streamingMedia.playVideo(this.video_url, options);
}
Problem:
Is it possible I am doing something wrong with path? Shouldn't video_url
show the video file?
This is the error I am getting after console.log(res[0])
:
Not allowed to load local resource: file:///storage/emulated/0/DCIM/Camera/VID_20221205_130100.mp4
Other useful log details :
MediaFile {
name: 'VID_20221205_130100.mp4',
localURL: 'cdvfile://localhost/sdcard/DCIM/Camera/VID_20221205_130100.mp4',
type: 'video/mp4',
lastModified: null,
lastModifiedDate: 1670238065000,
…
}
end: 0
fullPath: "file:///storage/emulated/0/DCIM/Camera/VID_20221205_130100.mp4"
lastModified: null
lastModifiedDate: 1670238065000
localURL: "cdvfile://localhost/sdcard/DCIM/Camera/VID_20221205_130100.mp4"
name: "VID_20221205_130100.mp4"
size: 7316613
start: 0
type: "video/mp4"
[[Prototype]]: File
app/tablinks/upload:1
Thanks