在Android应用程序中使用ExoPlayer API进行视频播放[页10]
来源:
时间: 2023-08-23
阅读:
java// Create a subtitle format factory and a subtitle media source factory.
Format subtitleFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP,
Format.NO_VALUE, null);
MediaSource subtitleSource = new SingleSampleMediaSource.Factory(new DefaultDataSourceFactory(
context, "user-agent")).createMediaSource(Uri.parse("http://example.com/my-subtitle.srt"), subtitleFormat,
C.TIME_UNSET);
// Attach the subtitle view to the player.
player.setSubtitleView(subtitleView);
// Set the subtitle media source on the player.
player.addMediaSource(subtitleSource);
上述代码创建了一个SingleSampleMediaSource.Factory对象,该对象用于创建SRT格式的字幕源。 然后,我们将SubtitleView附加到播放器,并将字幕源添加到播放器中。