-
Notifications
You must be signed in to change notification settings - Fork 146
getMetaInfo
shixuemei edited this page Sep 28, 2017
·
3 revisions
在播放过程中,获取当前播放文件的媒体信息,或当前播放的音频、视频、字幕轨道的媒体信息
v2.5.2及以上的版本可支持该功能
重点说明:如果将shouldEnableKSYStatModule参数设置为NO,getMetadata的接口将会返回nil;如果需要该信息,请务必将该参数设置为YES,或者不设置,默认值即为YES
- (NSDictionary *)getMetadata:(MPMovieMetaType)metaType
MPMovieMetaType定义如下:
typedef NS_ENUM(NSInteger, MPMovieMetaType) {
///当前播放文件的Meta
MPMovieMetaType_Media = 0,
///当前播放的视频Meta
MPMovieMetaType_Video,
///当前播放的音频Meta
MPMovieMetaType_Audio,
///当前播放的字幕Meta
MPMovieMetaType_Subtitle,
};
目前可支持查询的关键字如下:
kKSYPLYFormat -- 当前文件格式
kKSYPLYHttpFirstDataTime -- Http播放首包到达时间
kKSYPLYHttpAnalyzeDns -- Http播放DNS解析时间
kKSYPLYHttpConnectTime -- Http播放建链时间
kKSYPLYStreams -- 当前文件中的媒体流
kKSYPLYStreamType -- 当前流类型
kKSYPLYCodecName -- 媒体流编码类型
kKSYPLYStreamIndex -- 媒体流索引
kKSYPLYVideoWidth -- 视频帧宽度
kKSYPLYVideoHeight -- 视频帧高度
kKSYPLYAudioSampleRate -- 音频采样率
kKSYPLYAudioChannelLayout -- 音频声道布局
kKSYPLYAudioChannels -- 音频声道数
- 当参数metaType为MPMovieMetaType_Media时,该方法与
- (NSDictionary *)getMetadata
相同 - 当参数metaType为MPMovieMetaType_Media时,得到的meta是当前文件的所有meta信息
- 当参数metaType为MPMovieMetaType_Video/MPMovieMetaType_Audio/MPMovieMetaType_Subtitle时,得到的meta是当前播放的视频/音频/字幕流meta信息
- 字幕包含内嵌字幕和外挂字幕两种类型,可通过关键字
kKSYPLYStreamType
的值来区分,内嵌字幕为"subtitle", 外挂字幕为"external_timed_text"
//获取meta信息
NSDictionary *meta = [_player getMetadata];
if(meta){
//获取当前文件格式
NSString *metaString = [NSString stringWithFormat:@"format:%@\n", [mediaMeta objectForKey:kKSYPLYFormat]];
//获取所有流
NSMutableArray *streams = [meta objectForKey:kKSYPLYStreams];
for(NSDictionary *stream in streams) {
//获取流类型
NSString *streamType = [stream objectForKey:kKSYPLYStreamType];
//获取流编码类型
NSString *codecName = [stream objectForKey:kKSYPLYCodecName];
//获取当前流索引
NSInteger streamIndex = [[stream objectForKey:kKSYPLYStreamIndex] integerValue];
if([streamType isEqualToString:@"video"]) {
//获取视频宽高信息
NSInteger width = [[stream objectForKey:kKSYPLYVideoWidth] integerValue];
NSInteger height = [[stream objectForKey:kKSYPLYVideoHeight] integerValue];
metaString = [metaString stringByAppendingFormat:@"video: %ld %@ %ld*%ld\n", streamIndex, codecName, width, height];
}else if([streamType isEqualToString:@"audio"]) {
//获取音频声道数、采样率信息
NSInteger channels = [[stream objectForKey:kKSYPLYAudioChannels] integerValue];
NSInteger samplerate = [[stream objectForKey:kKSYPLYAudioSampleRate] integerValue];
metaString = [metaString stringByAppendingFormat:@"Audio: %ld %@ %ld %ld\n", streamIndex, codecName, channels, samplerate];
}else if([streamType isEqualToString:@"subtitle"])
metaString = [metaString stringByAppendingFormat:@"Subtitle: %ld %@\n", streamIndex, codecName];
else if([streamType isEqualToString:@"external_timed_text"])
metaString = [metaString stringByAppendingFormat:@"external_timed_text: %ld %@\n", streamIndex, codecName];
}
}