-1

Hello I want to show a simple Toast Message when a video being played in a Video View in android reaches half of its total duration. What kind of a Listener do I have to have in place to achieve this? I am aware of get getduration and getcurrentposition methods of Video View. But these wont help unless there is a listener in place which is reading the playback. As far as I know onprepared listener is used before the video starts and oncompletion listener is used once the video finishes playing. Any pointers and snippets are welcome.

D'yer Mak'er
  • 1,632
  • 5
  • 24
  • 47

1 Answers1

3

As far as I recall, there's no way to get a notification at a certain time (unless they are in newish APIs). What I would do is onPrepared, get the duration of the video, then implement polling at around the halfway mark. When getCurrentPosition() returns the point at 50%, show your Toast.

Matt
  • 3,837
  • 26
  • 29
  • thanks for the response. I have got the duration of the video. actually I want to show various toasts at various intervals during the video. 25%, 50% and 75% to be precise. How do I achieve such polling? – D'yer Mak'er Jul 11 '14 at 14:39
  • if you have the duration of the video, you can guess when 25 % will be reached, and use a handler, a timer or whatever mechanism to run something at this point. You'd still need to know when the user changes the position on the track, though. – njzk2 Jul 11 '14 at 14:43
  • http://stackoverflow.com/questions/24697344/monitoring-video-progress-in-android This is what I want to achieve. Sadly the question went unnoticed. – D'yer Mak'er Jul 11 '14 at 14:54
  • Thanks Matt! Your answer helped me in building my logic. – D'yer Mak'er Jul 17 '14 at 09:26