首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android -什么数据结构来存储视频字幕,以便在O(1)时间内获得它们

问Android -什么数据结构来存储视频字幕,以便在O(1)时间内获得它们
EN

Stack Overflow用户
提问于 2014-03-10 01:57:50
回答 1查看 423关注 0票数 3

我在我的申请中播放一个视频,我必须在上面显示字幕。字幕位于一个单独的smi文件中,这是一种提供字幕信息的XML标记。字幕文件如下所示:

代码语言:javascript
复制
.
.
.
<sync start=104600>
            <P Class=GBR><i></i><span ID=style1_0><i>Born of cold and 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 and fair...</i> </span></P>
        </sync>
.
.
.
.

start是在视频顶部显示字幕的时间,以毫秒为单位。现在,我正在解析使用regex并创建一个ArrayList of SubtitleChunk,其中包含与其相关的startTime和内容。

代码语言:javascript
复制
class SubtitleChunk {
    long startTime;
    String content;
}

现在,在显示视频时,我已经启动了一个单独的线程,我正在使用它,从数组获取字幕并显示它。以下是逻辑

代码语言:javascript
复制
public void run() {
    while (!isFinished_) {
            if (subtitleContent != null && subtitleContent.content_ != null) {
                for (int i = 0; i < 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 {

                }
            }
        });
    }
}

正如您所看到的,我正在ArrayList上运行一个循环,并将字幕的时间与我觉得太贵的moviePlayer_.getCurrentTimeMillis()进行比较。字幕落后,与视频不同步。

以上都是对这个问题的解释。现在问题..。我该如何改进呢?以O(1)时间获得某一特定时间的字幕。

编辑

我带着间隔树,这就是我需要把字幕放进去的地方:我从这里得到的:https://github.com/phishman3579/java-algorithms-implementation

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-11 19:21:05

更新:只是为了被接受:-)从我的评论中取消。

startTime相对于视频的开头。因此,相对于开始,人们知道视频中的一个在哪里。如果当前相对时间在一定范围内,那么我就可以得到字幕。我不确定来自Java库的任何数据结构是否会有帮助。看看段树/间隔树。它会给你更多的洞察力,我希望这可能会有所帮助。其想法是对SMI文件进行预处理。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22290874

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档