首页 > 解决方案 > 来自画廊的视频未加载到 iOS 离子角度应用程序上

问题描述

我正在尝试从图库中选择一个视频。我可以选择它,我只能在 Android 设备上播放,不能在 iOS 上播放。而且我不明白这个错误。它没有在 iOS 上加载。它返回错误:[object Object]

我在离子角度项目上使用 Cordova 文件和相机离子插件

这是我的 ts 文件。

import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { File, FileEntry } from '@ionic-native/file/ngx';

...

public files = [];

  public options_select_video: CameraOptions = {
    allowEdit: true,
    correctOrientation: false,
    destinationType: this.camera.DestinationType.FILE_URI,
    sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
    mediaType:this.camera.MediaType.VIDEO,    
  }



 ngOnInit() {
    if (this.hasCordova) {
      this.platform.ready().then(() => {
        let path = this.file.dataDirectory;
        this.file.checkDir(path, MEDIA_FOLDER_NAME).then(
            () => {
              this.loadFiles();
            },
            err => {
              this.file.createDir(path, MEDIA_FOLDER_NAME, false);
            }
        );
      });
    }
  }

loadGallery() {                 
        this.camera.getPicture(this.options_select_video).then(
          (data) => {
            console.log(data)
            let duration = data.duration();
         if (data.length > 0) {
           this.copyGalleryFileToLocalDir(data);
         }
       },
       (err: CaptureError) => console.error(err)
     );
     }


 copyGalleryFileToLocalDir(data) {
  console.log('CopyFileIsCalled', data )

  let myPath = data;
  // Make sure we copy from the right location
  if (data.indexOf('file://') < 0) {
    myPath = 'file://' + data;
  }

  const ext = myPath.split('.').pop();
  const d = Date.now();
  const newName = `${d}.${ext}`;

  const name = myPath.substr(myPath.lastIndexOf('/') + 1);
  const copyFrom = myPath.substr(0, myPath.lastIndexOf('/') + 1);
  const copyTo = this.file.dataDirectory + MEDIA_FOLDER_NAME;
  console.log('copyFrom, name, copyTo, newName', copyFrom, name, copyTo, newName)

  this.file.copyFile(copyFrom, name, copyTo, newName).then(
      success => {
        this.loadFiles();
      },
      error => {
        console.log('error: ', error);
      }
  );
}

 loadFiles() {
    console.log('LoadFIlesIsCalled')
    this.file.listDir(this.file.dataDirectory, MEDIA_FOLDER_NAME).then(
        res => {
          this.files = res;
        },
        err => {
          console.log('error loading files: ', err);
        }
    );
  }

.html 文件:

<ion-item-sliding *ngFor="let f of files">
    <!-- <span (click)="sendTest(f)"> stuur </span> -->
    <ion-item>
      <ion-icon name="play-outline" slot="start" *ngIf="f.name.endsWith('MOV') || f.name.endsWith('mp4')" (click)="openFile(f)"></ion-icon>
      <ion-icon name="trash-outline" slot="end" (click)="showDeleteAlert()"></ion-icon>
      <ion-label class="ion-text-wrap">
        <p>{{ f.name }}</p>
        <!-- <p>{{ f.fullPath }}</p> -->
      </ion-label>
    </ion-item>

 <ion-button (click)="loadGallery()"></ion-button>

控制台日志:

copyFrom, name, copyTo, newName 
file:///private/var/mobile/Containers/Data/PluginKitPlugin/AB52B0D2-BAF4-40B3-94E8-D867B96EE4D5/tmp/ 
trim.2B60B823-213D-4383-BA3B-275D88DDB7D5.MOV file:///var/mobile/Containers/Data/Application/B7E63CD1-13A8-419D-87E3-D73622467899/Library/NoCloud/my_media 
1628244858483.MOV

它在 Android 上运行良好,在 iOS 上停止并返回错误。在 copyGalleryFileToLocalDir()

任何提示或帮助将不胜感激!谢谢!

标签: angularcordovaionic-frameworkvideocamera

解决方案


推荐阅读