从具有 src 的 phonegap 应用程序中的视频标签下载视频
Download video from the video tag in my phonegap app which has src
我正在添加一个下载按钮以从我的 phonegap android 应用程序下载视频。
如何从我的应用
中的视频标签将视频下载到我的 android 存储空间
我必须知道完成此功能的优化方式
function videoDownload(){
//find the first element with video tag in current screen
var video = document.getElementsByTagName("video")[0];
//video.src gives url as expected
console.log(video.src);
//show download progress for user
//download video to the storage
const url = video.src
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
// the filename you want
a.download = 'share-video.mp4';
document.body.appendChild(a);
a.click();
}
提前致谢
您需要先安装cordova-plugin-file-transfer to get started with your file download. Then you need to call the download()的插件才能下载文件。下面是一个可以实现下载的示例代码,但是很明显,你需要提供真实的网址才能下载成功。
function downloadAsset() {
var fileTransfer = new FileTransfer();
var assetURL = 'your_video_url'; // is video.src string
//for android app
var fileName = '/storage/emulated/0/Android/data/[package-name]/files' + 'new_name'; // is share-video.mp4
fileTransfer.download(assetURL, fileName,
function(entry) {
console.log("Success!");
},
function(err) {
console.log("Error");
});
}
我正在添加一个下载按钮以从我的 phonegap android 应用程序下载视频。 如何从我的应用
中的视频标签将视频下载到我的 android 存储空间我必须知道完成此功能的优化方式
function videoDownload(){
//find the first element with video tag in current screen
var video = document.getElementsByTagName("video")[0];
//video.src gives url as expected
console.log(video.src);
//show download progress for user
//download video to the storage
const url = video.src
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
// the filename you want
a.download = 'share-video.mp4';
document.body.appendChild(a);
a.click();
}
提前致谢
您需要先安装cordova-plugin-file-transfer to get started with your file download. Then you need to call the download()的插件才能下载文件。下面是一个可以实现下载的示例代码,但是很明显,你需要提供真实的网址才能下载成功。
function downloadAsset() {
var fileTransfer = new FileTransfer();
var assetURL = 'your_video_url'; // is video.src string
//for android app
var fileName = '/storage/emulated/0/Android/data/[package-name]/files' + 'new_name'; // is share-video.mp4
fileTransfer.download(assetURL, fileName,
function(entry) {
console.log("Success!");
},
function(err) {
console.log("Error");
});
}