aspose file tools
The moose likes Other JSE/JEE APIs and the fly likes Simple JMF question - help needed urgently! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "Simple JMF question - help needed urgently!" Watch "Simple JMF question - help needed urgently!" New topic
Author

Simple JMF question - help needed urgently!

Tom Pelly
Greenhorn

Joined: Jun 29, 2001
Posts: 14
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

Joined: Dec 02, 2001
Posts: 8
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

Joined: Jun 29, 2001
Posts: 14
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

Joined: Dec 02, 2001
Posts: 8
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

Joined: Jun 29, 2001
Posts: 14
Thanks alot for the help, I'll go and try to give it a go...
amit mawkin
Ranch Hand

Joined: Oct 31, 2001
Posts: 73
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.


regards,<br />Amit<br />coffee drinker<br />-----------------------<br />Sun Certified Programmer for Java 2 Platform
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Simple JMF question - help needed urgently!
 
Similar Threads
Storing numbers as variable type long
Object creation
iterate to all List type property of my objects recursively
Can you please explain the syntax
determining an object class is an array, list etc