I use videoview to display following video https://ellovidsout.s3.amazonaws.com/877/9/1421668953.mp4.m3u8
At the end of the video I check getCurrentPosition()
vs getDuration()
.
The current position is 219418.0. While getDuration
returns 205000.0.
So duration is 14 seconds less then real length. That also happens with my other video.

- 43
- 4
1 Answers
The getDuration() method of VideoView calculates the duration according to the duration that is declared in the .m3u8 manifest for each .ts file.
So, if the declaration is not accurate there will be a difference between getDuration() and the actual duration as you observe it by using getCurrentPosition().
Your .m3u8 example file is actually a 'playlist manifest' that refers to 3 different .m3u8 stream manifests (selected according to bandwidth), so if we look at one of the stream manifests it refers to, it will look like this:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:11
#EXTINF:10.880000,
1000k_1421668953.mp400000.ts
#EXTINF:10.800000,
1000k_1421668953.mp400001.ts
#EXTINF:10.800000,
1000k_1421668953.mp400002.ts
#EXTINF:10.800000,
1000k_1421668953.mp400003.ts
#EXTINF:7.200000,
1000k_1421668953.mp400004.ts
#EXTINF:10.800000,
1000k_1421668953.mp400005.ts
...
The '#EXTINF:10.880000' above each .ts link is the .ts duration declaration that is used by getDuration() to sum the total video duration.
By the way, when I ran my code with this video, the duration I got by using getDuration() was actually 199330, which is slightly different from what you observed back then. But this is exactly the sum of all the duration declarations.

- 1,285
- 1
- 16
- 39