AVFoundation播放视频时显示字幕,切换音轨
2016-05-12 09:05
441 查看
主要用到两个类:AVMediaSelectionGroup 和 AVMediaSelectionOption
调用 AVAsset对象的availableMediaCharacteristicsWithMediaSelectionOptions会返回一个数组,这个数组包含视频中备用的媒体资源,AVMediaCharacteristicLegible字幕资源,AVMediaCharacteristicAudible 音轨资源,AVMediaCharacteristicVisual 视频资源。
显示字幕和切换音轨方法都是一样的,这里以显示字幕为例:
1. AVMediaSelectionGroup*group =[asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
for(AVMediaSelectionOption*option in group.options) {
NSLog(@"%@",option.displayName);
}
NSLocale*locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
2. NSArray*options = [AVMediaSelectionGroup mediaSelectionOptionsFromArray:group.options withLocale:locale];
3. [playItem selectMediaOption:options.firstObject inMediaSelectionGroup:group];
1.获取可用的字幕资源。
2016-03-03 15:08:15.438 VideoPlayer[13403:1004146]英文
2016-03-03 15:08:15.441 VideoPlayer[13403:1004146]英文Forced
2016-03-03 15:08:15.441 VideoPlayer[13403:1004146]意大利文
2016-03-03 15:08:15.442 VideoPlayer[13403:1004146]意大利文Forced
2016-03-03 15:08:15.442 VideoPlayer[13403:1004146]葡萄牙文
2016-03-03 15:08:15.443 VideoPlayer[13403:1004146]葡萄牙文Forced
2016-03-03 15:08:15.443 VideoPlayer[13403:1004146]俄文
2016-03-03 15:08:15.443 VideoPlayer[13403:1004146]俄文Forced
2.获取指定地区的字幕资源。
3. 添加指定字幕到播放器中。
文/yoolooo(简书作者)
原文链接:http://www.jianshu.com/p/5f147f40f9f3
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
调用 AVAsset对象的availableMediaCharacteristicsWithMediaSelectionOptions会返回一个数组,这个数组包含视频中备用的媒体资源,AVMediaCharacteristicLegible字幕资源,AVMediaCharacteristicAudible 音轨资源,AVMediaCharacteristicVisual 视频资源。
显示字幕和切换音轨方法都是一样的,这里以显示字幕为例:
1. AVMediaSelectionGroup*group =[asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
for(AVMediaSelectionOption*option in group.options) {
NSLog(@"%@",option.displayName);
}
NSLocale*locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
2. NSArray*options = [AVMediaSelectionGroup mediaSelectionOptionsFromArray:group.options withLocale:locale];
3. [playItem selectMediaOption:options.firstObject inMediaSelectionGroup:group];
1.获取可用的字幕资源。
2016-03-03 15:08:15.438 VideoPlayer[13403:1004146]英文
2016-03-03 15:08:15.441 VideoPlayer[13403:1004146]英文Forced
2016-03-03 15:08:15.441 VideoPlayer[13403:1004146]意大利文
2016-03-03 15:08:15.442 VideoPlayer[13403:1004146]意大利文Forced
2016-03-03 15:08:15.442 VideoPlayer[13403:1004146]葡萄牙文
2016-03-03 15:08:15.443 VideoPlayer[13403:1004146]葡萄牙文Forced
2016-03-03 15:08:15.443 VideoPlayer[13403:1004146]俄文
2016-03-03 15:08:15.443 VideoPlayer[13403:1004146]俄文Forced
2.获取指定地区的字幕资源。
3. 添加指定字幕到播放器中。
文/yoolooo(简书作者)
原文链接:http://www.jianshu.com/p/5f147f40f9f3
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
相关文章推荐
- 浏览器突然不能上网了?
- 冒泡排序优化算法(复杂度是n2)
- 让高度百分比,height:100% 生效的3种方法
- Servlet和HTTPServlet的区别
- loadrunner:Action.c(4): Error -27796: Failed to connect to server "192.168.66.3:8080": [10060] Connection timed out
- Spring对ORM的支持之集成Hibernate3
- 第六次作业
- 《剑指offer》-栈的压入、弹出序列
- PropertyPlaceholderConfigurer的用法
- Binder
- Spring MVC的RequestParam注解
- 12 个非常有用的 JavaScript 技巧
- BroadcastReceiver源码解析(一)
- 创业的第一百八十天
- cannot return from outside a function or method
- Python基于二分查找实现求整数平方根的方法
- STM32F1和STM32F4 区别
- pyte模块
- 《Linux驱动》最简单的驱动编写与makefile
- Myeclipse中SVN版本与客户端版本出现冲突问题与解决方法