uniapp 安卓选择手机中的mp3文件怎么做
在uni-app中,可以使用uni.chooseImage或uni.chooseFile方法选择手机中的mp3文件。
- 使用uni.chooseFile方法选择文件:
uni.chooseFile({
count: 1, // 最多可以选择的文件数量,默认9
type: 'all', // 可选择文件的类型,如image/video/audio,默认为所有文件类型
success: function(res) {
// 选择文件成功
console.log(res.tempFilePaths[0]); // mp3文件的临时路径
},
fail: function(err) {
// 选择文件失败
console.log(err);
}
});
- 使用uni.chooseImage方法选择图片,然后将后缀名为mp3的文件过滤出来:
uni.chooseImage({
count: 1, // 最多可以选择的图片数量,默认9
success: function(res) {
// 选择图片成功
console.log(res.tempFilePaths); // 图片的临时路径数组
// 遍历临时路径数组,过滤出后缀名为mp3的文件
var mp3Files = res.tempFilePaths.filter(function(path) {
return path.toLowerCase().endsWith('.mp3');
});
console.log(mp3Files[0]); // mp3文件的临时路径
},
fail: function(err) {
// 选择图片失败
console.log(err);
}
});
这两种方法都可以选择手机中的mp3文件,并获取到文件的临时路径
原文地址: https://www.cveoy.top/t/topic/hYFg 著作权归作者所有。请勿转载和采集!