Created
April 9, 2025 19:16
-
-
Save thinkphp/67677c185e8417d67be3245ee7de9c2a to your computer and use it in GitHub Desktop.
TaggedFile Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package player; | |
import java.util.Map; | |
public class TaggedFile extends SampleFile { | |
private String album; | |
public void readAndStoreTags() { | |
Map<String, Object> tagMap = TagReader.readTags(getPathname()); | |
//citim titlurile | |
if(tagMap.containsKey("title")) { | |
Object titleObj = tagMap.get("title") ; | |
if(titleObj != null) this.title = titleObj.toString(); | |
} | |
//citire autor | |
if(tagMap.containsKey("author")) { | |
Object authorObj = tagMap.get("author"); | |
if(authorObj!=null) this.author = authorObj.toString(); | |
} | |
//citire album | |
if(tagMap.containsKey("album")) { | |
Object albumObj = tagMap.get("album"); | |
if(albumObj!=null) this.albumObj.toString(); | |
} | |
//read duration | |
if(tagMap.containsKey("duration")) { | |
Object durationObj = tagMap.get("duration"); | |
if(durationObj != null) { | |
if(durationObj instanceof Long) { | |
this.duration = (Long)durationObj; | |
} else if(durationObj instanceof Number) { | |
this.duration = (Number)durationObj.longValue(); | |
} else { | |
try{ | |
this.duration = Long.parseLong(durationObj.toString()); | |
}catch(NumberFormatException e){ | |
/// | |
} | |
} | |
} | |
} | |
} | |
public String getAlbum() { | |
return album; | |
} | |
@Override | |
public String toString() { | |
String baseStr = super.toString(); | |
if(album!=null && !album.isEmpty()) return baseStr + " - "+ album + " - " + formatDuration(); | |
else return baseStr + " - " + formatDuration(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment