【问题标题】:Convert PHAsset/AVAsset to mp4 video in Nativescript app在 Nativescript 应用程序中将 PHAsset/AVAsset 转换为 mp4 视频
【发布时间】:2019-08-07 13:57:30
【问题描述】:

我使用nativescript-imagepicker-plugin 作为文件选择器。 这将返回一个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。

【问题讨论】:

    标签: javascript ios nativescript phasset avasset


    【解决方案1】:

    你的语法似乎是错误的

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

    【讨论】:

    • 谢谢!所以我有一个错字并且误解了找到的 objC 代码-ecample
    猜你喜欢
    • 2015-12-25
    • 1970-01-01
    • 2015-06-14
    • 2015-11-07
    • 1970-01-01
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    相关资源
    最近更新 更多