简体   繁体   English

使用媒体捕获cordova插件录制视频并上传到远程服务器问题

[英]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.

相关问题 使用Cordova Media插件时出现问题 - Issue in using Cordova Media plugin 使用Javascript AWS开发工具包将使用Cordova Media Capture插件捕获的视频上传到S3 - Uploading to S3 a video captured using Cordova Media Capture plugin using Javascript AWS SDK phoneGap / Apache Cordova媒体捕获插件-多个视频录制 - phoneGap/Apache Cordova media capture plugin - multiple video recording 使用外部Java插件在PhoneGap / Cordova中进行音频/视频捕获 - Audio/Video Capture in PhoneGap/Cordova using external Java plugin Cordova Media-Capture 插件不工作 - Cordova Media-Capture plugin is not working 使用Cordova应用程序上传文件在远程服务器上不起作用 - File upload using cordova app not working on remote server 使用媒体捕获cordova插件在ionic 4应用程序中录制音频 - Recording audio inside ionic 4 app using media-capture cordova plugin 在html元素中显示Cordova-media-capture视频提要? - Show Cordova-media-capture video feed in a html element? 如何在DIV中显示Cordova媒体捕获视频提要? - How to show Cordova-media-capture video feed in a DIV? 如何显示使用cordova-plugin-media-capture捕获的图像 - How to display an image captured with cordova-plugin-media-capture
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM