-
Notifications
You must be signed in to change notification settings - Fork 247
selectTrack
dengchu817 edited this page Nov 2, 2017
·
5 revisions
播放器支持多音轨切换,下面将介绍相关的接口以及调用示例
播放SDK:v2.0.1及以上
- 获取音轨信息
打开带有音轨的文件时,可以获取到当前视频文件内的所有音轨信息
/**
* 获取当前音视频轨道信息
* @return KSYTrackInfo包含了音(视)轨的信息
**/
public KSYTrackInfo[] getTrackInfo()
2.切换音轨
/**
* 开启某(视频、音频、字幕)流
* @param trackIndex 流索引
*/
public void selectTrack(int trackIndex)
/**
* 关闭某(视频、音频、字幕)流
* @param trackIndex 流索引
*/
public void deselectTrack(int trackIndex)
KSYTextureView mKsyTextureView;
// 获取当前多媒体文件的音视频轨道信息
KSYTrackInfo[] trackInfos = mKsyTextureView.getTrackInfo();
private ArrayList<KSYTrackInfo> mTrackList = new ArrayList<>();
for (KSYTrackInfo info : trackInfos) {
switch(info.getTrackType()) {//获取流类型(视频、音频、字幕)
case ITrackInfo.MEDIA_TRACK_TYPE_AUDIO:
// 获取每个音轨的 索引 以及语种(如果流信息里没有语种信息,获取语种会失败)
mTrackList.add(info);
Log.d("KSYMediaPlayer", "Audio Track Index:"+info.getTrackIndex()+", language:"+info.getLanguage());
break;
}
}
//切换音轨
ArrayAdapter<KSYTrackInfo> adapter = new ArrayAdapter<KSYTrackInfo>(this, android.R.layout.simple_list_item_1, mTrackList);
ListView mStreamInfoList = (ListView) view.findViewById(...);
mStreamInfoList.setAdapter(adapter);
mStreamInfoList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ITrackInfo info = mTrackList.get(position);
if (mKsyTextureView == null)
return;
int index = mKsyTextureView.getSelectedTrack(ITrackInfo.MEDIA_TRACK_TYPE_AUDIO);// 获取当前正在播放的音频轨道索引
if (info.getTrackType() == ITrackInfo.MEDIA_TRACK_TYPE_AUDIO && index != info.getTrackIndex()){
mKsyTextureView.selectTrack(info.getTrackIndex());
}
}
});