dictionary - Android - What data structure to store video subtitles to get them in O(1) time -


i playing video in application , have show subtitles on top of that. subtitles in separate smi file sort of xml markup provides subtitle information. subtitle file looks this:

. . . <sync start=104600>             <p class=gbr><i></i><span id=style1_0><i>born of cold , winter air</i> </span><br><i></i><span id=style1_0><i>and mountain rain combining.</i> </span></p>         </sync>         <sync start=107080>             <p class=mys>&nbsp;<br></p>         </sync>         <sync start=107200>             <p class=mys><i></i><span id=style2_0><i>...serta hujan di pergunungan.</i> </span></p>         </sync>         <sync start=110840>             <p class=mys>&nbsp;<br></p>             <p class=gbr>&nbsp;<br></p>         </sync>         <sync start=111160>             <p class=sim>&nbsp;<br></p>         </sync>         <sync start=111480>             <p class=gbr><i></i><span id=style1_0><i>this icy force</i> </span><br><i></i><span id=style1_0><i>both foul , fair...</i> </span></p>         </sync> . . . . 

the start time in milliseconds when show subtitle on top of video. parsing using regex , creating arraylist of subtitlechunk contains starttime , content associated it.

class subtitlechunk {     long starttime;     string content; } 

now while showing video have started separate thread using subtitle array , show it. following logic

public void run() {     while (!isfinished_) {             if (subtitlecontent != null && subtitlecontent.content_ != null) {                 (int = 0; < length; i++) {                     subtitlechunk subchunk1 = null;                     subtitlechunk subchunk2 = null;                     try {                         subchunk1 = subtitlecontent.content_.get(i);                         subchunk2 = subtitlecontent.content_.get(i + 1);                          long ctime = movieplayer_.getcurrenttimemillis();                         if (ctime > subchunk1.starttime && (subchunk2 == null || ctime < subchunk2.starttime)) {                             currentsub = subchunk1.content;                             currentchunk = subchunk1;                             break;                         }                     } catch (exception e) {                         debugutil.printlogexception(view_log_tag, e);                         currentsub = "";                     }                 }             } else {                 currentsub = "";             }          } catch (interruptedexception e) {             e.printstacktrace();         } catch (exception e) {             e.printstacktrace();         }          new handler(looper.getmainlooper()).post(new runnable() {             public void run() {                 if (movieplayer_.isplaying()) {                     subtitletextview.settext(html.fromhtml(currentsub));                 } else {                  }             }         });     } } 

as can see, running loop on arraylist , comparing time of subtitles movieplayer_.getcurrenttimemillis() feel expensive. , subtitles lagging , not in sync video.

all above explaination of issue. , question.. how can improve it? subtitle specific time in o(1) time.

edited

i went interval trees, thats needed put subtitles in: got here: https://github.com/phishman3579/java-algorithms-implementation

updated: accepted :-) lifted comment.

starttime relative beginning of video. so, 1 know 1 in video relative start. if current relative time lies in range, can subtitle. not sure if data-structure java library can helpful. take @ segment tree/interval tree. give more insight.i hope might helpful. idea preprocess smi file


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -