this.mediaContainer.extractDataSource({
source: url,
success: (res) => {
uni.showLoading({
title: '正在下载...',
mask: true
})
let mediaTrack = null;
let audioTrack = null;
for (let i = 0; i < res.tracks.length; i++) {
if (res.tracks[i].kind == 'video') {
mediaTrack = res.tracks[i];
}
if (res.tracks[i].kind == 'audio') {
audioTrack = res.tracks[i];
}
}
this.mediaContainer.addTrack(mediaTrack);
this.mediaContainer.addTrack(audioTrack);
this.mediaContainer.export({
success: (data) => {
let {
tempFilePath
} = data;
this.src = tempFilePath;
uni.hideLoading()
this.mediaContainer.removeTrack(mediaTrack)
this.mediaContainer.removeTrack(audioTrack)
wx.saveVideoToPhotosAlbum({
filePath: tempFilePath,
success(result) {
console.log(result, "保存成功");
},
fail(err) {
console.log(err, "保存失败");
}
})
},
fail: (err) => {
uni.hideLoading();
this.showtt('下载失败')
}
});
},
fail: (err) => {
console.log(err, "视频源分离失败");
}
});