AVPlayer隐藏式字幕打开/关闭 [英] AVPlayer Closed Captions turn on/off

查看:362
本文介绍了AVPlayer隐藏式字幕打开/关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建自定义视频播放器,并且想为CC创建切换按钮.

我看到了这篇文章: IOS AVPlayer无法禁用隐藏式字幕

所以我尝试了:

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冻结在屏幕上.

谢谢!

解决方案

目标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];
   

I'm creating custom video player, and i want to create toggle button for CC.

I saw this post : IOS AVPlayer cannot disable closed captions

So I tried :

AVMediaSelectionGroup *group = [self.avPlayer.currentItem.asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];

[self.avPlayer.currentItem  selectMediaOption:nil inMediaSelectionGroup:group];

Didn't work.. cc still visible.

also tried :

AVPlayerItemLegibleOutput *output = [[AVPlayerItemLegibleOutput alloc] init];
[output setDelegate:self queue:dispatch_get_main_queue()];
[output setSuppressesPlayerRendering:true];
[self.avPlayer.currentItem addOutput:output];

It's hide the the cc, but how can I unhide them? ,I tried:

[output setSuppressesPlayerRendering:true];

but the cc freeze on the screen.

thanks!

解决方案

Objective C: This one works for me. Even I wanted to do the same thing.

To off subtitles

AVMediaSelectionGroup *subtitleSelectionGroup = [_playerItem.asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
              
[_playerItem selectMediaOption:NULL inMediaSelectionGroup:subtitleSelectionGroup];

To show it again I do this:

AVMediaSelectionOption* option = [subtitleSelectionGroup.options objectAtIndex:subtitleIndex-1]; // I did -1 because OFF was 0 for my case 
         
[_playerItem selectMediaOption:option inMediaSelectionGroup:subtitleSelectionGroup];
   

这篇关于AVPlayer隐藏式字幕打开/关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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