2017-03-23 42 views
-1
public Track createNewTrack(File file) throws IOException { 
    Path path = file.toPath(); 
    String trackName = (String) Files.getAttribute(path, "Title"); //get name of track from file 
    String artist = (String) Files.getAttribute(path, "Authors"); //get artist from file 
    String filePath = file.getPath(); //get file path from file 
    Track track = new Track(trackName, artist, filePath); 
    return track; 
} 

由於某種原因,它沒有找到該屬性...任何人都可以幫助我,爲什麼這可能是?如何獲取MP3文件'標題'和'作者'的屬性

回答

-1

A 文件可以是一個不同於MP3文件。所以它並不總是具有這些屬性和類不提供它們。

你必須自己閱讀這些屬性。請參閱:How to read MP3 file tags

-1

Files.getAttribute讀取文件系統屬性; mp3元數據在文件系統中通常不可用,但使用ID3格式存儲在文件內容中。你需要一個理解ID3的庫。

相關問題