iOS Question Add subtitle to VideoPlayer?

hatzisn

Well-Known Member
Licensed User
Longtime User
I think it can be done easily the same way this guy does it with no extra library. He adds a label above the view and a timer to check which subtitle has to be displayed. The rest is simple logic as with each timer_tick you check the player's position and just as simply you display the appropriate subtitle. I would start by preloading the subtitle in memory in order to be done on the fly. Read each subtitle and add it to a Map with keys "timestart", "timeend", "sub2show". Add this map to a list. In each tick go through the list and get the appropriate sub. No need to traverse through the entire list. Just keep the last list position in a variable and start from the immediately next. If the immediately next's time frame, is much greater than the player's position (let's say more than 10 seconds) this means that the user has seeked back so set last list's position to zero and call the sub that searches for the appropriate subtitle in the list. Show your appreciation to this contribution by creating a b4xlib with a custom view (there are instructions in the forum) and posting it in the forum.

EDIT - I have never used the VideoPlayer and if there is an event that you can exploit to know if the user seeks in the VideoPlayer then the checking of the 10 seconds gap is of no use. Just ignore it.
 
Last edited:
Upvote 0

mehdipass

Member
I think it can be done easily the same way this guy does it with no extra library. He adds a label above the view and a timer to check which subtitle has to be displayed. The rest is simple logic as with each timer_tick you check the player's position and just as simply you display the appropriate subtitle. I would start by preloading the subtitle in memory in order to be done on the fly. Read each subtitle and add it to a Map with keys "timestart", "timeend", "sub2show". Add this map to a list. In each tick go through the list and get the appropriate sub. No need to traverse through the entire list. Just keep the last list position in a variable and start from the immediately next. If the immediately next's time frame, is much greater than the player's position (let's say more than 10 seconds) this means that the user has seeked back so set last list's position to zero and call the sub that searches for the appropriate subtitle in the list. Show your appreciation to this contribution by creating a b4xlib with a custom view (there are instructions in the forum) and posting it in the forum.

EDIT - I have never used the VideoPlayer and if there is an event that you can exploit to know if the user seeks in the VideoPlayer then the checking of the 10 seconds gap is of no use. Just ignore it.
Hi,
Thanks
Can you please give me an example how do it?
 
Upvote 0
Top