JavaFX에서 MP3 플레이어를 만들고 지금까지 노래를로드하고 재생하려고했지만 이제 Media 객체의 메타 데이터를 tableview에 표시하려고합니다. 모델 클래스의 역할을하는 노래 클래스가 있고 컨트롤러 클래스에 레이블이 있습니다. 메타 데이터를 표시 할 수 있는지 테스트 중이지만 항상 null로 나타납니다. 메타 데이터가 정확하게 검색하고 항상 null의 경우 내가 테스트하고 마지막 줄에 내 컨트롤러 클래스Media 객체에서 메타 데이터를 가져 오는 방법
// Event Listener on Button[#loadBtn].onAction
@FXML
public void loadFile(ActionEvent event) {
Node source = (Node) event.getSource();
Window theStage = source.getScene().getWindow();
//set fileChooser filter
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("MP3 files", "*.mp3");
fileChooser.getExtensionFilters().add(extFilter);
fileChooser.setTitle("Select MP3 files");
//File file = fileChooser.showOpenDialog(theStage);
//mySong = new Song(file);
list = fileChooser.showOpenMultipleDialog(theStage);
if(list!=null){
for(File x: list) {
mySong = new Song(x);
}
}
label.setText(mySong.getTitle());
}
에서
package application;
import java.io.File;
import javafx.collections.MapChangeListener;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
public class Song {
private File file;
private String title;
private String artist;
private String album;
private Media music;
private MediaPlayer mp;
public Song(File file) {
music = new Media(file.toURI().toString());
mp = new MediaPlayer(music);
getMeta();
artist = (String) mp.getMedia().getMetadata().get("artist");
title = (String) music.getMetadata().get("title");
album = (String) music.getMetadata().get("album");
//artist = "test";
//album = "test";
//title = "test";
}
public void play() {
mp.play();
}
public void pause() {
mp.pause();
}
public void stop() {
mp.stop();
}
public String getTitle(){
return title;
}
public String getArtist(){
return artist;
}
public String getAlbum(){
return album;
}
}
. 처음에는 "테스트"라고 말하기 위해 레이블을 설정 했으므로 변경 사항이 있는지 그리고 원하는지 알 수 있습니다. 그러나 원하는 것은 아닙니다. documentation (내 강조) 당으로
내가 솔루션을 시도하고 여전히 어쩌면 내 mp3 파일 메타 데이터가없는, 오직 내가 생각할 수있는 이유는 작동하지 나타 납니까? http://imgur.com/a/F4xQx 하지만 그럴 것 같습니다. –
'if (c.wasAdded()) {System.out.println (c.getKey() + ":"+ c .getValueAdded())}'어떤 메타 데이터가 전혀 선택되지 않았는지 확인하십시오. 16 진수 편집기가 있다면 MP3 파일을 열고 거기에 [ID3 tags] (https://en.wikipedia.org/wiki/ID3)가 있는지 확인할 수 있습니다. –
그래, "노래"수업에서 메타 데이터를 집어 들고 있지만 'code'System.out.println ("노래 제목 :"+ mySong.getArtist());'코드 ' 을 실행하면 컨트롤러 클래스 출력 "노래 제목 : null" 출력하는 노래 클래스에서 "아티스트 : Foo Fighters 앨범 : Saint Cecilia EP 제목 : Saint Cecilia" get 메소드가 null을주는 이유는 무엇입니까? –