In my project, I have a video section in which I want to calculate the percentage of time the user will watch. Through the below URL can access the details of video
URL : video/video_id output:
"video": {
"id": "84e7288c-dc09-44aa-850c-08546a98ffde",
"deleted": null,
"datetime_created": "02/04/2022 06:56 AM",
"datetime_updated": "02/04/2022 06:56 AM",
"video_name": "video name3",
"description": "description about video",
"duration": "00:33:20",
"create_date": "02/04/2022 06:56 AM",
"video_type": "micro",
"file_url": "https://vimeo.com/216763352",
"general_status": "high",
"review_status": "draft",
"video_number": "VD6129",
"created_by": null
},
"duration": "00:33:20" is the total duration of video. How to calculate the percentage of video time that the user is watching, if passing the time in total seconds like
{
"time":200
}
Well, I have recently done something like that, my task was to calculate the video watched time and give points accordingly. I was also asked not to give percentage and points for watched video time. I used merge algorithm to merge overlapping intervals. You can customize the code for your task requirements, because you may not be asked to give user points and make unique 100% accurate calculation like I did, here is what I have done:
models.py
views.py
serializers.py
NOTE that you can optimize and remove unnecessary parts for your own video calculation logic. This can also be used for audio calculation logic. I don't usually share source code, but just because I really want to help, I did it, cheers)