UNIAPP獲取本地文件完整教程
loadDir() { let environment = plus.android.importClass("android.os.Environment"); // 判斷SD卡是否插入(涉及到SDK的讀取,最好先判斷SDK是否插入) // environment.getExternalStorageState() === environment.MEDIA_MOUNTED // 獲得sd卡根目錄 let path = environment.getExternalStorageDirectory().getAbsolutePath(); this.rootPath = path; let lastPath = uni.getStorageSync('lastPath'); // 如果上次打開(kāi)過(guò)目錄,則使用上次的路徑 if (lastPath) { path = lastPath; } this.getFiles({ fullPath: path + '/Vpi視頻', isFile: false }); }, /** * 獲取文件夾內(nèi)容 */ getFiles(file) { if (!file.isFile) { let dirs = [], files = []; let directory = new File(file.fullPath); let arr = directory.listFiles(); arr.forEach(item => { if (!item.isHidden()) { if (item.isDirectory()) { dirs.push({ name: item.getName(), fullPath: item.getPath(), isFile: false, }) } else { // 文件 var filename = item.getName() var parts = filename.split("."); if (parts[1] == 'mp3') { files.push({ title: parts[0], fileUrl: item.getPath(), isFile: true, // 是否是文件 mid: "", epname: "", singer: "", }) } } } }) //console.log(files) this.audioList = files this.getdata(files[0]) if (this.Openif) { this.Openif = false } else { this.Openif = true } } },
[聲明]原創(chuàng)不易,請(qǐng)轉(zhuǎn)發(fā)者備注下文章來(lái)源(hbsjsd.cn)【速建時(shí)代】。