本文首发于抖音开放平台社区
分享开发经验瓜分5000元大奖,聊聊#我写代码那些年#的故事
保存图片也是类似的逻辑。
新写的代码,欢迎帮忙补充完善。
function saveVideo(opt) {
var cb = opt;
downloadFile({
url: opt.url,
success: function (res) {
var curImgTmp = res.tempFilePath;
tt.authorize({
scope: "scope.album",
success: function () {
opt.path = curImgTmp;
var idx = curImgTmp.lastIndexOf(".");
var ext = curImgTmp.substring(idx + 1);
if (ext == "qt") {
var filePath = "ttfile://user/tmpforsave.mov";
var fs = tt.getFileSystemManager();
fs.saveFileSync(curImgTmp, filePath);
opt.path = filePath;
}
saveVideoToLocal(opt);
},
fail: function () {
//这里发个打开访问相册权限的提醒
cb.authFail();
}
});
},
fail: function () {
cb.fail();
}
});
}
function saveVideoToLocal(opt) {
var cb = opt;
tt.saveVideoToPhotosAlbum({
filePath: cb.path,
success: function (res) {
cb.success();
},
fail: function (res) {
//这里发个失败提示
cb.fail();
}
});
}