angular - 来自画廊的视频未加载到 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()
任何提示或帮助将不胜感激!谢谢!
解决方案
推荐阅读
- ios - React Native Firebase Cloud Messaging 在构建 RN 0.63.4 时抛出错误
- jestjs - 使用 react-testing-library 测试错误状态时,如何抑制预期的 Axios 错误消息?
- mocha.js - Mocha 侧边栏 vscode 扩展不会自动刷新测试
- flutter - 如何在 GButton (google_nav_bar) 中使用自定义小部件(网络图像)?
- asp.net-core - 具有公司 AD Windows 身份验证的 Blazor wasm 托管应用程序
- python - 将多个 CSV 加载到单个 pandas 数据框中
- python - 我收到“[Errno 2] No such file or directory”错误代码,即使我有直接/绝对路径....有什么建议吗?
- python - 如何计算数字数组的对数阶乘
- c++ - lambda 中的“变量阴影”警告(未捕获时)
- python - 将 Mobilenet 模型转换为 TFLite 会更改输入大小