Hi,
The getDuration() method returns -1 if the MediaPlayer is not yet prepared.
The best way to call the VideoView or MediaPlayer's getDuration() is after
they are prepared, ie. in their onPrepared() call or after that.
This is possible in MediaPlayer in the current SDK and will be possible in
the VideoView in one of the future releases of the SDK. You cannot get the
exact duration in VideoView using the getDuration() method, currently as the
PreparedListener for VideoView is not available. Is the use of duration
mandatory in your application?
Thanks,
Megha
2008/3/23 fry <[EMAIL PROTECTED]>:
>
> Hi Megha,
>
> Glad to hear about the fixed bug with recorded files, hope the bugfix
> version of SDK (without broken API :)) would appear before the
> contests deadline.
>
> For the duration - I call it in this way:
> videoView.setVideoPath("/the_path/videosample2.3gp");
> int videoDuration = videoView.getDuration();
>
> If I understand correctly, videoView.setVideoPath(..) blocks until the
> file is loaded, so getDuration call should be ok in this case. With
> this code videosample2.3gp plays rather fine (I can see the movie),
> but the reported duration is -1.
>
> I have just checked the VideoViewDemo code - it has 2 lines I do not
> have in my code:
> mVideoView.setMediaController(new MediaController(this));
> mVideoView.requestFocus();
>
> Still did not have a chance to check them in runtime, probably they
> would change something.
>
> On Mar 23, 10:49 pm, "Megha Joshi" <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > At what point are you calling getDuration() method? Please include the
> code
> > here...
> >
> > The bug about the files recorded with MediaRecorder, not being played by
> > MediaPlayer has been fixed.
> > It will work in the next release of the SDK( I mentioned this a couple
> of
> > times on this group earlier :) )
> >
> > Thanks,
> > Megha
> >
> > 2008/3/23 fry <[EMAIL PROTECTED]>:
> >
> >
> >
> > > Hello,
> >
> > > I also use MediaPlayer (and with the new version of SDK switched to
> > > VideoView) in my application to play video files - they both also
> > > return '-1' as file duration for me. Previous version of SDK
> > > MediaPlayer did return correct value. Another problem is that in the
> > > new version of SDK MediaPlayer stopped playing files recorded by
> > > MediaRecorder (those green-and-purple chessboards) - I was able to do
> > > this in the previous version of SDK. If no one already did this, I'm
> > > going to post a bugreport for that during the next week or so, did not
> > > check the attached samples yet, can I consider them as official
> > > google's Media API examples?
> >
> > > On Mar 23, 7:56 pm, fishman <[EMAIL PROTECTED]> wrote:
> > > > hello Megha
> > > > i use the MediaPlayer's getDuration(), but it always return -1.
> > > > And it can play sound file successfully. How can i get this file's
> > > > length ? the testing file type is mp3
> > > > could you please give me some information ?
> >
> > > > On 3月20日, 上午8時12分, Megha <[EMAIL PROTECTED]> wrote:
> >
> > > > > The sample applications for using Media APIs:
> >
> > > > > 1) MediaPlayerTest
> > > > > 2) MediaRecorder
> > > > > 3) VideoViewDemo
> >
> > > > > are uploaded in the Group's Files section:
> > >http://groups.google.com/group/android-developers/files
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---