javascript - 在 Nativescript 应用程序中将 PHAsset/AVAsset 转换为 mp4 视频

标签 javascript ios nativescript phasset avasset

我使用nativescript-imagepicker-插件作为文件选择器。 这将返回一个 PHAsset。 我必须将其复制到临时目录才能上传。 我是 iOS 新手,所以我尝试了一下:

const options = PHVideoRequestOptions.new();
options.version = PHVideoRequestOptionsVersion.Current;
PHImageManager
    .defaultManager()
    .requestAVAssetForVideoOptionsResultHandler(
        phAsset
        , options
        , (avAsset, audioMix, info) => {
            try {

                const tempFilePath = path.join(tempFolderPath, `${Date.now()}.mp4`);
                const targetURL = NSURL.fileURLWithPath(tempFilePath);
                const exportSession = AVAssetExportSession.alloc(avAsset, AVAssetExportPresetPassthrough);
                exportSession.outputUrl = targetURL;
                exportSession.outputFileType = AVFileTypeMPEG4;
                exportSession.exportAsynchronouslyWithCompletionHandler(() => {
                    console.log(exportSession.status);
                });
            }
            catch (e) {
                console.log(e);
            }
        }
    );

我的代码崩溃了,没有错误,所以我不知道从哪里开始调试。 我想要一个 MP4,也可以在网络上显示。

最后,我需要一个 mp4 文件的字符串(路径)来使用 nativescript-background-http 上传 id。

最佳答案

你的语法似乎有问题

const exportSession = AVAssetExportSession.alloc().initWithAssetPresetName(avAsset, AVAssetExportPresetPassthrough);
exportSession.outputURL = targetURL;

关于javascript - 在 Nativescript 应用程序中将 PHAsset/AVAsset 转换为 mp4 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57396145/

相关文章:

ios - 从 Apple iTunes Connect 删除应用程序版本

javascript - Nativescript ListView [object 对象]

javascript - 获取GDrive中文件和文件夹之间的联系

javascript - 当选项是对象时选择选项的最佳方式是什么?

javascript - 如何根据文本框 vue.js 上的指定数量添加行

javascript - 自定义指令中的 ng-class 不观察更新

ios - 使用 ARKit 加载的 3d 文件有大小限制吗?

iphone - 单个对象,多个 IBOutlets

android - 我的 Android 设备无法使用 tns 预览扫描 CLI 中生成的二维码

javascript - NativeScript UI 构建器