我使用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/