Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get javafx media metadata without listener
    text
    copied!<p>so I've been looking for this for a week now and reading though every problem similar but none seemed to ask the same problem as mine exactly(try reverse engineering other solution similar to what I want with no success.</p> <p>explained caveman style: I'm trying to create list using Metadata.</p> <ol> <li>I open with a multi dialog and select more than one mp3</li> <li>I put the file in an <code>ArrayList&lt;File&gt;</code></li> <li>I loop though the files with an enhanced for loop and extract metadata using a media variable</li> <li>The info for the metadata ( like "artist") is what i want to save in an ArrayList for example</li> </ol> <p>the problem is that the listener only works way after the enhanced loop has finished which results in <code>ArrayList&lt;String&gt;</code> having one object with nothing in it </p> <p>here is a sample:</p> <pre><code>ArrayList&lt;String&gt; al; String path; public void open(){ files=chooser.showOpenMultipleDialog(new Stage()); for( File f:files){ path=f.getPath(); Media media = new Media("file:/"+path.replace("\\", "/").replace(" ", "%20")); al= new ArrayList&lt;String&gt;(); media.getMetadata().addListener(new MapChangeListener&lt;String, Object&gt;() { public void onChanged(Change&lt;? extends String, ? extends Object&gt; change) { if (change.wasAdded()) { if (change.getKey().equals("artist")) { al.add((String) change.getValueAdded()); } } } }); }//close for loop //then i want to see the size of al like this system.out.println(al.size()); //then it returns 1 no matter how much file i selected //when i system out "al" i get an empty string </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload