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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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.