Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48979

The video from gallery is not loaded on iOS ionic angular app

$
0
0

I am trying to choose a video from gallery. I can choose it and I can play it only on Android device not on iOS. And I don’t understand the error. It’s not loaded on iOS. It returns error: [object Object]

I am using Cordova File and Camera ionic plugins on ionic angular project

Here is my ts file.

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 file:

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

THE CONSOLE LOG:

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

It works fine on Android, it stops on iOS and returns error. On copyGalleryFileToLocalDir()

Would appreciate any tip or help! Thanks!

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48979

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>