Android 如何在Cordova中获取mp3信息
我用ApacheCordova为android创建了一个音乐播放器,我在尝试从MP3中获取歌曲信息艺术家、专辑时遇到了一个障碍。 我试着只使用目录结构一个目录从mp3=album,两个目录向上=artist,但这是不可靠的。 因此,现在我一直在尝试从mp3文件中读取ID3信息,以获取艺术家和专辑标签,但我尝试的一切要么都是空白,要么是应用程序崩溃。有什么想法吗Android 如何在Cordova中获取mp3信息,android,cordova,Android,Cordova,我用ApacheCordova为android创建了一个音乐播放器,我在尝试从MP3中获取歌曲信息艺术家、专辑时遇到了一个障碍。 我试着只使用目录结构一个目录从mp3=album,两个目录向上=artist,但这是不可靠的。 因此,现在我一直在尝试从mp3文件中读取ID3信息,以获取艺术家和专辑标签,但我尝试的一切要么都是空白,要么是应用程序崩溃。有什么想法吗 document.addEventListener("deviceready", function () { window.requ
document.addEventListener("deviceready", function () {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fsSuccess);
function fsSuccess(fs){
console.log(fs);
var dirURL = fs.root.nativeURL;
directoryPath = dirURL.replace("file://", "");
gotPath(directoryPath)
}
function gotPath(directoryPath) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
fileSystem.root.getDirectory(directoryPath, {create: false, exclusive: false}, getDirSuccess);
})
}
function getDirSuccess(dirEntry) {
var directoryReader = dirEntry.createReader();
directoryReader.readEntries(readerSuccess);
}
function readerSuccess(entries) {
var i;
for (i=0; i<entries.length; i++) {
if(entries[i].isDirectory) {
directoryURL = entries[i].nativeURL;
directoryPath = directoryURL.replace("file://", "");
gotPath(directoryPath);
} if (entries[i].isFile){
if(entries[i].name.indexOf(".mp3") != -1){
var fileURL = entries[i].localURL.replace("file://", "");
ID3.loadTags(fileURL, function() {
var tags = ID3.getAllTags(fileURL);
alert(tags.artist);
},
{
tags: ["artist"]
},
{
dataReader: FileAPIReader(fileEntry.file)
});
}
}
}
}
}, false);
与您试图从文件中获取ID3信息的人共享代码如何?
$scope.getInfo = function (song) {
filePath = song.nativeURL;
file_URI = filePath.replace("file://", "");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
function gotFS(fileSystem) {
fileSystem.root.getFile(file_URI, null, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(fileEntry){
ID3.loadTags(fileEntry.localURL, function() {
var tags = ID3.getAllTags(fileEntry.localURL);
console.log(tags.artist + " " + tags.album + " " + tags.title + " " + tags.track);
},
{
tags: ["artist", "album", "track", "title"]
});
}
function fail(error) {
console.log(error.code);
}
};