[英]Record Video using Media capture cordova plugin and upload to remote server issue
I am working on cordova application in which i need to capture video or choose from gallery and upload it to the remote server.我正在开发cordova应用程序,我需要在其中捕获视频或从图库中选择并将其上传到远程服务器。 I have captured the video and it path is coming but i'm not able to see the video with url and impossible to send it to server too
我已经捕获了视频,它的路径即将到来,但我无法看到带有 url 的视频,也无法将其发送到服务器
` `
takeVideo() {
let options: CaptureVideoOptions = { limit: 1, duration: 15 }
this.mediaCapture.captureVideo(options)
.then(
(data: MediaFile[]) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
// let base64Image = 'data:image/jpeg;base64,' + imageData;
// alert(data[0].fullPath)
// this.copyFileToLocalDir(data[0].fullPath);
alert(data[0].fullPath)
this.dispVideos.push(data[0].fullPath)
},
(err: CaptureError) => {
alert(err)
}
);
}
` `
UPLOAD METHOD upload method上传方法上传方法
html html
<div *ngIf="dispVideos?.length > 0">
<video #myVideo preload="metadata" controls="false">
<source [src]="sanitizer.bypassSecurityTrustResourceUrl(dispVideos[0])" type="video/mp4">
</video>
</div>
to display the video you have to insert显示您必须插入的视频
this.dispVideos.push((window as any).Ionic.WebView.convertFileSrc(data[0].fullPath));
I also recently found an error on ios with the apache cordova camera plugin it provides the temporary path to the video file to come out from this error implement below changes in camera plugin.我最近还发现 ios 上的 apache cordova 相机插件错误,它提供了视频文件的临时路径,以便从相机插件更改下方的此错误实现中出来。
in CDVCamera.m change THIS:在 CDVCamera.m 中改变这个:
(CDVPluginResult*)resultForVideo:(NSDictionary*)info
{
NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] absoluteString];
return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];
}
to THIS:到这个:
(CDVPluginResult*)resultForVideo:(NSDictionary*)info
{
NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSArray* spliteArray = [moviePath componentsSeparatedByString: @"/"];
NSString* lastString = [spliteArray lastObject];
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp"];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:lastString];
[fileManager copyItemAtPath:moviePath toPath:filePath error:&error];
return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.