This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 21 - Pages: 2 [ Previous | 1 2 ] - Last Post: 4 May 22, 16:28 Last Post By: RobM Threads: [ Previous | Next ]
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Having no luck with MediaUtils.getDuration()
Posted: 4 May 22, 14:13   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
The code "under the hood" within MediaUtil looks very similar to your old code....

Not surprising - most of that came from you in the first place. I had no hope of getting through it on my own.
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: Having no luck with MediaUtils.getDuration()
Posted: 4 May 22, 15:37   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
davidekholm wrote:
The code "under the hood" within MediaUtil looks very similar to your old code....

Not surprising - most of that came from you in the first place. I had no hope of getting through it on my own.


Understandable. Multi threaded trickery can be challenging.
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: Having no luck with MediaUtils.getDuration()
Posted: 4 May 22, 15:49   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Other fun things to explore using this API is the getMetadata() call, which delivers author, title and copyright info for mp3:s. Here's a little code snippet I used to copy such info from attached audio clips to jAlbum's objects:
Work.on(selectedObjects).
  forEach(ao) -> {
  		File clip = ao.getAudioClip();
  		if (clip != null) {
  			m = MediaUtil.loadMedia(clip);
  			meta = m.getMetadata();
  			ao.title = meta.title;
  			ao.comment = "Sound courtesy of " + new String(meta.artist.getBytes("iso-8859-1"), "utf-8") + ", " + meta.album;
  		}
  }

Resulting gallery: https://davidekholm.jalbum.net/Birds/
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Having no luck with MediaUtils.getDuration()
Posted: 4 May 22, 16:02   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Just a little problem with that album. I clicked on the first thumbnail. The audio autoplays, and there's a slideshow running. But it appears that the audio is set to loop, so it never ends. Therefore, without manual intervention, you never get to the second image.

This stuff is fiendishly tricky. ;)

And audio with no control bar is an assault.

ETA: Or maybe the sound clips are just very long. Without a visible control bar, there's no way to know. And shouldn't the automated slideshow resume when the clip is finished? But what if the visitor pauses the slideshow manually? Should the slideshow resume on its own when the clip is finished, or should it wait for the user to do something? And if there is a control bar, what if the user pauses the audio? Should the slideshow resume, or should it wait for him to finish listening to the clip?

See what I mean?
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Having no luck with MediaUtils.getDuration()
Posted: 4 May 22, 16:03   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Other fun things to explore using this API is the getMetadata() call, which delivers author, title and copyright info for mp3:s. Here's a little code snippet I used to copy such info from attached audio clips to jAlbum's objects:
Work.on(selectedObjects).
  forEach(ao) -> {
  		File clip = ao.getAudioClip();
  		if (clip != null) {
  			m = MediaUtil.loadMedia(clip);
  			meta = m.getMetadata();
  			ao.title = meta.title;
  			ao.comment = "Sound courtesy of " + new String(meta.artist.getBytes("iso-8859-1"), "utf-8") + ", " + meta.album;
  		}
  }

Resulting gallery: https://davidekholm.jalbum.net/Birds/
This seems much easier than using JavaFX
 Media media = new Media(ao.getFile().toURI().toString());
	//System.out.println("media file = " + media);
	MediaPlayer mp = new MediaPlayer(media);
	mp.setOnReady(new Runnable() {
		public void run() {
			ObservableMap metadata = media.getMetadata();
                        if(metadata.get("composer") != null //do stuff
From my old tool to get mp3 metadata
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: Having no luck with MediaUtils.getDuration()
Posted: 4 May 22, 16:21   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
davidekholm wrote:
Other fun things to explore using this API is the getMetadata() call, which delivers author, title and copyright info for mp3:s. Here's a little code snippet I used to copy such info from attached audio clips to jAlbum's objects:
Work.on(selectedObjects).
  forEach(ao) -> {
  		File clip = ao.getAudioClip();
  		if (clip != null) {
  			m = MediaUtil.loadMedia(clip);
  			meta = m.getMetadata();
  			ao.title = meta.title;
  			ao.comment = "Sound courtesy of " + new String(meta.artist.getBytes("iso-8859-1"), "utf-8") + ", " + meta.album;
  		}
  }

Resulting gallery: https://davidekholm.jalbum.net/Birds/
This seems much easier than using JavaFX
 Media media = new Media(ao.getFile().toURI().toString());
	//System.out.println("media file = " + media);
	MediaPlayer mp = new MediaPlayer(media);
	mp.setOnReady(new Runnable() {
		public void run() {
			ObservableMap metadata = media.getMetadata();
                        if(metadata.get("composer") != null //do stuff
From my old tool to get mp3 metadata

True, even though I'm using JavaFX under the hood. Your callbacks can however be expressed more easily using "lambda" expressions if you're using compiled Java or Groovy:
Media media = new Media(ao.getFile().toURI().toString());
	//System.out.println("media file = " + media);
	MediaPlayer mp = new MediaPlayer(media);
	mp.setOnReady(() -> {
		ObservableMap metadata = media.getMetadata();
        if(metadata.get("composer") != null //do stuff
        ...
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Having no luck with MediaUtils.getDuration()
Posted: 4 May 22, 16:28   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
RobM wrote:
davidekholm wrote:
True, even though I'm using JavaFX under the hood. Your callbacks can however be expressed more easily using "lambda" expressions if you're using compiled Java or Groovy:
Media media = new Media(ao.getFile().toURI().toString());
	//System.out.println("media file = " + media);
	MediaPlayer mp = new MediaPlayer(media);
	mp.setOnReady(() -> {
		ObservableMap metadata = media.getMetadata();
        if(metadata.get("composer") != null //do stuff
        ...
Groovey GUI is too slow for as many options as the tool has, I think I have only got about two tools to work well enough.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums