Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple JMF question - help needed urgently!

 
Tom Pelly
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Does anyone know a simple way how to get the total running time of an audio/video file without creating a MediaPlayer object?
I've tried looking at using a DataSource object, but it's an abstract class so can't be used.
Please help!
Thanks.
 
Hoang Hai
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tom,
I didn't try it, but I see that DataSource implements Duration, and Duration has method
getDuration : ( cut n paste from JMF2.1.1 API documentation )
public Time getDuration()
Get the duration of the media represented by this object. The value returned is the media's duration when played at the default rate. If the duration can't be determined (for example, the media object is presenting live video) getDuration returns DURATION_UNKNOWN.
Returns:
A Time object representing the duration or DURATION_UNKNOWN.
Hope this helps
 
Tom Pelly
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but Duration is an interface so I can't use it as a instance. And DataSource is an abstract class - it doesn't actually have the method getDuration() in it.
How can I use any of these classes to help me?
Thanks.
 
Hoang Hai
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tom,
- you can use Manager.createDataSource(URL) with URL is the URL of your media file.
- Then call getDuration() on the DataSource you've just created.
- see Duration API to use getSeconds() or getNanoseconds() methods.
- There's an easy way to get a File object (and then call toURL() to pass it to createDataSource method ), that's to use JFileChooser (swing).
experiment to get the correct duration of the media file, that's the thing you have to do after all above's done (I tried the above but the duration I got is not as I want, but I'm busy now to do further ;p )
good luck
 
Tom Pelly
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot for the help, I'll go and try to give it a go...
 
amit mawkin
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Create a Player instance like
Player player;
double d=player.getDuration.getSecond();
This will get you the toatal time of the media in seconds and after getting that you can do whatever you like with it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic