繁体   English   中英

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

[英]Record Video using Media capture cordova plugin and upload to remote server issue

我正在开发cordova应用程序,我需要在其中捕获视频或从图库中选择并将其上传到远程服务器。 我已经捕获了视频,它的路径即将到来,但我无法看到带有 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)
        }
      );
  }

`

上传方法上传方法

html

  <div *ngIf="dispVideos?.length > 0">
        <video #myVideo preload="metadata" controls="false">
          <source [src]="sanitizer.bypassSecurityTrustResourceUrl(dispVideos[0])" type="video/mp4">
        </video>
      </div>

显示您必须插入的视频

this.dispVideos.push((window as any).Ionic.WebView.convertFileSrc(data[0].fullPath));

我最近还发现 ios 上的 apache cordova 相机插件错误,它提供了视频文件的临时路径,以便从相机插件更改下方的此错误实现中出来。

在 CDVCamera.m 中改变这个:

(CDVPluginResult*)resultForVideo:(NSDictionary*)info
{
NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] absoluteString];
return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];
}

到这个:

(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM