Set subtitles using AVPlayer

I managed to display the subtitle track from AVPlayer on iOS 6, but I can’t configure it. It just shows the same style (small font size, white).

Here, as I select the subtitles:

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

And how am I trying to adjust the subtitles:

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

Regardless of whether I place this fragment before or after selecting subtitles, the result will be the same.

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

Any thoughts on how to do this?

+7
ios objective-c ios6 avplayer
source share
2 answers

I asked this question in the Apple Developer Forums, and I received a response from an Apple employee:

The textStyleRules property applies only to WebVTT content. Your local file may contain subtitles in TX3G format.

You are correct that the documentation does not mention this restriction, so you must indicate an error so that we can update our documentation.

So, I will open the radar to ask them to update the documents, and I will send his number here if someone wants to trick him.

EDIT

I created rdar: // 14923673 to ask Apple to update documents about this current restriction. I also created rdar: // 14923755 to ask them to provide support for subtitles in TX3G format.

Please trick them if you are affected by this problem.

+8
source share

I found a workaround for correctly changing the color and background of the foreground text. Just separate styles for multiple AVTextStyleRule.

 func initSubtitleStyle() { let textStyle:AVTextStyleRule = AVTextStyleRule(textMarkupAttributes: [ kCMTextMarkupAttribute_CharacterBackgroundColorARGB as String: [0.2,0.3,0.0,0.3] ])! let textStyle1:AVTextStyleRule = AVTextStyleRule(textMarkupAttributes: [ kCMTextMarkupAttribute_ForegroundColorARGB as String: [0.2,0.8,0.4,0.0] ])! let textStyle2:AVTextStyleRule = AVTextStyleRule(textMarkupAttributes: [ kCMTextMarkupAttribute_BaseFontSizePercentageRelativeToVideoHeight as String: 20, kCMTextMarkupAttribute_CharacterEdgeStyle as String: kCMTextMarkupCharacterEdgeStyle_None ])! player.currentItem?.textStyleRules = [textStyle, textStyle1, textStyle2] } 

please do not ask me why this solution comes from try and error XD

0
source share

All Articles