是否可以在 iPhone 上播放视频并显示与其同步的字幕?
我想为 iPhone 应用程序中播放的视频添加“字幕”。我不希望将这些字幕编码到视频本身中 - 理想情况下,我希望有一个显示视频的视图(带有暂停、播放、音量和此类标准控件)以及显示随电影时间一起变化的文本的视图改变。
如果我画的话,就是这样的
所以,基本上,我需要一种方法来获取电影播放时调用的方法,然后同步标签上显示的文本以及电影时间。
有人使用过能够做到这一点的解决方案吗?
I want to add a "subtitles" to a video played in an iPhone app. I don't want those subtitles encoded into the video itself - ideally I'd love to have a view showing the video (with pause, play, volume and such standard controls) together with a view displaying the text that changes together with movie time changing.
If I drawn that, it's something like this,
So, basicly, I would need a way to get a method called when movie is playing, and then synchronize the text displayed on the label with the movie timing.
Anyone used a solution that was able to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近做了一些将图形与音轨中的时间同步的事情。我的方法是使用 MPMediaPlayback 接口的 currentPlaybackTime 属性(MoviePlayer 控制器也应该符合该属性)。这将返回媒体中经过的秒数,以
double
形式(类型定义为NSTimeInterval
)。我的应用程序中的实际同步不是在通知中完成的,因为我找不到任何类似“滴答声”的内容,而是创建了一个计时器,调用一个函数查询 currentPlaybackTime,并据此更新图形。就您的实现而言,我假设您有某种将标签文本(字幕)与特定时间相关联的系统。然后,您可以将文本的时间范围与 currentPlaybackTime 返回的时间进行比较,以找到要显示的正确文本。
I've recently done something that syncs graphics to times in an audio track. The way I did it was by using the currentPlaybackTime property of the MPMediaPlayback interface (which the MoviePlayer controller should also conform to). This returns the seconds elapsed in the media, in a
double
(typedef'ed asNSTimeInterval
). The actual synchronisation in my app was not done in notifications, as I couldn't find any resembling a "tick", but instead I created a timer, calling a function queried the currentPlaybackTime, and updated the graphics based on this.In terms of your implementation, I would assume you have some kind of system for associating label text (subtitles) with a particular time. You could then compare the text's time range with the time returned from currentPlaybackTime to find the correct text to display.