【问题标题】:Record Video using Media capture cordova plugin and upload to remote server issue使用 Media capture cordova 插件录制视频并上传到远程服务器问题
【发布时间】:2021-01-15 04:53:44
【问题描述】:

我正在开发 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)
        }
      );
  }

`

上传方式 upload method

html

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

【问题讨论】:

    标签: javascript angular typescript cordova ionic-framework


    【解决方案1】:

    要显示您必须插入的视频

    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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多