使用AVPlayer自定义字幕 [英] Customizing subtitles with AVPlayer

查看:1482
本文介绍了使用AVPlayer自定义字幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够在iOS 6上显示带 AVPlayer 的字幕轨道,但我无法自定义它。它只显示相同的样式(小字体,白色)。

I was able to display a subtitle track with AVPlayer on iOS 6, but I am not able to customize it. It just shows the same style (a small font size, in white).

以下是我选择字幕的方式:

Here's how I select the subtitle:

AVMediaSelectionGroup *subtitle = [asset mediaSelectionGroupForMediaCharacteristic: AVMediaCharacteristicLegible];
[self.videoPlayer.currentItem selectMediaOption:subtitle.options[0] inMediaSelectionGroup: subtitle];

以及我如何尝试自定义字幕:

And how I'm trying to customize the subtitle:

AVTextStyleRule *rule = [[AVTextStyleRule alloc] initWithTextMarkupAttributes:@{
                         (id)kCMTextMarkupAttribute_ForegroundColorARGB : @[ @1, @1, @0, @0 ],
                         (id) kCMTextMarkupAttribute_ItalicStyle : @(YES)}];

self.videoPlayer.currentItem.textStyleRules = @[rule];

无论我在选择字幕之前还是之后都放了这个片段,结果都是一样的。

No matter if I put this snippet before or after selecting the subtitle, the result is the same.

使用本地(文件)URL(mp4文件)创建 AVPlayer

The AVPlayer is created with a local (file) URL (a mp4 file).

有关如何执行此操作的任何想法?

Any thoughts on how to do this?

推荐答案

我在Apple开发者论坛上提出这个问题我从Apple员工处获得答案

I asked this question on Apple Developer Forums and I got an answer from an Apple employee:


textStyleRules 属性仅适用于WebVTT内容。您的本地文件可能带有TX3G格式的字幕。

The textStyleRules property only applies to WebVTT content. Your local file is probably carrying subtitles in TX3G format.

你说文档没有提到这个限制是对的,所以你应该提交一个bug,这样我们就可以更新我们的文档了。

You're right that the documentation doesn't mention this limitation, so you should file a bug so we can get our documentation updated.

所以,我会打开一个雷达,询问他们是否更新了文档,如果有人想欺骗它,我会在这里发布它的号码。

So, I'll open a radar to ask that they update the docs and I'll post its number here if someone wants to dupe it.

编辑

我创建了 rdar:// 14923673 要求Apple更新有关此当前限制的文档。我还创建了 rdar:// 14923755 ,要求他们为TX3G格式的字幕提供支持。

I created rdar://14923673 to ask Apple to update the docs about this current limitation. I also created rdar://14923755 to ask them to provide support to subtitles in TX3G format.

如果你受到这个问题的影响,请欺骗他们。

Please dupe them if you're affected by this issue.

这篇关于使用AVPlayer自定义字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆