我正在创建自定义视频播放器,我想为CC创建切换按钮。
我看过这篇文章:IOS AVPlayer cannot disable closed captions
所以我试过了:
AVMediaSelectionGroup *group = [self.avPlayer.currentItem.asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
[self.avPlayer.currentItem selectMediaOption:nil inMediaSelectionGroup:group];
没有工作...... cc仍然可见。
也尝试过:
AVPlayerItemLegibleOutput *output = [[AVPlayerItemLegibleOutput alloc] init];
[output setDelegate:self queue:dispatch_get_main_queue()];
[output setSuppressesPlayerRendering:true];
[self.avPlayer.currentItem addOutput:output];
它隐藏了cc,但我怎么能取消隐藏呢? ,我试过了:
[output setSuppressesPlayerRendering:true];
但cc屏幕冻结。
谢谢!
答案 0 :(得分:1)
目标C:这对我有用。甚至我也想做同样的事情。
关闭字幕
AVMediaSelectionGroup *subtitleSelectionGroup = [_playerItem.asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
[_playerItem selectMediaOption:NULL inMediaSelectionGroup:subtitleSelectionGroup];
要再次显示,请执行以下操作:
AVMediaSelectionOption* option = [subtitleSelectionGroup.options objectAtIndex:subtitleIndex-1]; // I did -1 because OFF was 0 for my case
[_playerItem selectMediaOption:option inMediaSelectionGroup:subtitleSelectionGroup];