【发布时间】:2019-03-14 05:32:18
【问题描述】:
我想用 exoplayer 2 显示预加载的字幕,并向播放器提供一个基于 webvtt 的字符串,以便它处理字幕。
我的系统应该这样工作:
- 我向服务器发送请求以获取字幕(加密)
- 我解密服务器响应得到一个字幕字符串(webvtt 格式)
- 我想将此字符串提供给 exoplayer。 Exoplayer 应该能够像我使用 webvtt uri 一样显示潜艇。
我不想使用系统文件,因为它会使用户可以访问字幕文件。
见下面我的活动代码:
//Class Player Activity
// ... activity code ...
public void initializePlayer(){
//... code intialization of player ...
mVideoEventListener = new VideoEventListener(this);
if(mEpisode.getVideo().getSubtitle() == null) {
mEpisode.getVideo().loadSubtitle(this, Video.VO, mVideoEventListener);
return;
}
hasSubtitle = true;
startPlayer();
}
public void startPlayer(){
boolean haveStartPosition = startWindow != C.INDEX_UNSET;
if (haveStartPosition) {
mPlayer.seekTo(startWindow, startPosition);
}
if(hasVideo && hasSubtitle){
MergingMediaSource mergedSource = new MergingMediaSource(mVideoSource, mSubtitleSource);
mPlayer.prepare(mergedSource, !haveStartPosition, false);
}
}
// ... activity code ...
private class VideoEventListener implements
Video.SubtitleListener,
LoadBalancer.OnLoadBalanceListener{
private final Context mCtx;
VideoEventListener(Context ctx) {
mCtx = ctx;
}
@Override
public void onSubtitleLoaded(String subtitle) {
hasSubtitle = true;
Format subtitleFormat = Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, C.SELECTION_FLAG_FORCED, "fr");
mSubtitleSource = //My problem : How create a mediaSource with variable "subtitle" in format WebVTT ?
startPlayer();
}
}
【问题讨论】:
标签: android subtitle exoplayer2.x