Hi I am using ionic 5 to develop mobile applications. As part of app I am using media capture plugin to record video and in call back storing file path in a variable and tried to play video using html5 video tag, I am getting issue like
"Not allowed to load local resource"
I am trying in android device. Any help would be appreciated. Below is my code:
html:
Sample App.ts file:
import { Component, OnInit } from ‘@angular/core’;
import { CameraPreview, CameraPreviewPictureOptions, CameraPreviewOptions, CameraPreviewDimensions } from ‘@ionic-native/camera-preview/ngx’;
import { MediaCapture, MediaFile, CaptureVideoOptions } from ‘@ionic-native/media-capture/ngx’;
import { VideoPlayer } from ‘@ionic-native/video-player/ngx’;
@Component({
selector: ‘app-visitor’,
templateUrl: ‘./visitor.page.html’,
styleUrls: [’./visitor.page.scss’],
})
export class VisitorPage implements OnInit {
camOptions: any;
video: any;
constructor(private camPreview: CameraPreview, private mediaCapture: MediaCapture) {
}
ngOnInit() {
}
ionViewWillEnter() {
}
camPreviewVideo() {
this.camOptions = {
x: 0,
y: 125,
width: window.screen.width,
height: window.screen.height - 150,
camera: ‘front’,
tapPhoto: false,
previewDrag: false,
toBack: false,
storeToFile: false,
alpha: 1
};
this.camPreview.startCamera(this.camOptions).then(resp => {
console.log('response ' + JSON.stringify(resp));
setInterval(() => this.captureVideo(), 2000);
}, err => {
console.log('Error ' + JSON.stringify(err));
});
}
captureVideo() {
var options = {
cameraDirection: this.camPreview.CAMERA_DIRECTION.FRONT,
width: window.screen.width,
height: window.screen.height - 205,
quality: 100,
withFlash: false
}
this.camPreview.startRecordVideo(options).then(resp => {
console.log('resp ', JSON.stringify(resp));
}, err => {
console.log('err ', JSON.stringify(err));
});
}
mediaCaptureVideo() {
let options: CaptureVideoOptions = {
limit: 1, duration: 30
};
this.mediaCapture.captureVideo(options).then((path: MediaFile[]) => {
console.log('path ', path[0].fullPath);
let win: any = window; // hack ionic/angular compilator
var myURL = win.Ionic.WebView.convertFileSrc(path[0].fullPath);
console.log('url ', myURL);
this.video = myURL
}, err => {
alert('Error Media Capture Video' + JSON.stringify(err));
});
}
}