本文整理汇总了Java中com.google.android.exoplayer2.source.SingleSampleMediaSource类的典型用法代码示例。如果您正苦于以下问题:Java SingleSampleMediaSource类的具体用法?Java SingleSampleMediaSource怎么用?Java SingleSampleMediaSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SingleSampleMediaSource类属于com.google.android.exoplayer2.source包,在下文中一共展示了SingleSampleMediaSource类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import com.google.android.exoplayer2.source.SingleSampleMediaSource; //导入依赖的package包/类
@Override
protected MediaSource[] doInBackground(MediaFile... media) {
try {
browser = Browser.getInstance(Config.mountDirectory);
DataSource.Factory dataSourceFactory = new NfsDataSourceFactory(browser.getContext());
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource videoSource = new ExtractorMediaSource(Uri.parse("nfs://host/" + media[0].getPath()), dataSourceFactory, extractorsFactory, null, null);
if (media[0].getSubtitlePath() != null) {
Format subtitleFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, null, Format.NO_VALUE, Format.NO_VALUE, "en", null);
MediaSource subtitleSource = new SingleSampleMediaSource(Uri.parse("nfs://host/" + media[0].getSubtitlePath()), dataSourceFactory, subtitleFormat, Long.MAX_VALUE, 0);
return new MediaSource[]{videoSource, subtitleSource};
} else
return new MediaSource[]{videoSource};
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例2: TextSubtitle
import com.google.android.exoplayer2.source.SingleSampleMediaSource; //导入依赖的package包/类
/**
* 加载字幕
* @param srtUri
* @param mediaSource
*/
private MediaSource TextSubtitle(Uri srtUri, MediaSource mediaSource){
Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP,
null, Format.NO_VALUE, Format.NO_VALUE, Locale.getDefault().getLanguage(), null);
MediaSource textMediaSource = new SingleSampleMediaSource(srtUri, mediaDataSourceFactory, textFormat, C.TIME_UNSET);
return new MergingMediaSource(mediaSource, textMediaSource);
}
示例3: onCreate
import com.google.android.exoplayer2.source.SingleSampleMediaSource; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
Bundle bundle = getIntent().getExtras();
if(bundle!=null && bundle.containsKey("multimedia")) {
Multimedia multimedia = bundle.getParcelable("multimedia");
SimpleExoPlayerView videoView = (SimpleExoPlayerView) findViewById(R.id.video);
// 1. Crea un slector de pista por defecto
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
// 2. Creo un control para el player
LoadControl loadControl = new DefaultLoadControl();
// 3. Creo el player con los componentes anteriores
player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl);
//Obtengo la URL completa del archivo de video
Uri uri = Uri.parse(ConsultasBBDD.server + ConsultasBBDD.imagenes + multimedia.getUrl());
//A la vista le establezco el reproductor que va a usar
videoView.setPlayer(player);
// Procuce que se instancie el DataSource a través de los datos del video que ha sido cargado.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(), Util.getUserAgent(getApplicationContext(), "SmartU"));
// Produce un extractor que parsea el video.
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
// Construyo un MediaSource con el formato y los datos del video para asignarselo al reproductor.
MediaSource videoSource = new ExtractorMediaSource(uri, dataSourceFactory, extractorsFactory, null, null);
// If has subtitles load video with subtitles
if (multimedia.getUrlSubtitulos() != null && multimedia.getUrlSubtitulos().compareTo("") != 0) {
//Obtengo la URL completa para los subtitulos del video
Uri subtitulosUri = Uri.parse(ConsultasBBDD.server + ConsultasBBDD.imagenes + multimedia.getUrlSubtitulos());
//Asigno el formato de los subtitulos
Format textFormat = Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT,
null, Format.NO_VALUE, Format.NO_VALUE, Locale.getDefault().getLanguage(), null);
//Creo un MediaSource para los subtitulos para añadirselos al video
MediaSource subtitleSource = new SingleSampleMediaSource(subtitulosUri, dataSourceFactory, textFormat, C.TIME_UNSET);
// Mezcla el video con los subtitulos
MergingMediaSource mergedSource = new MergingMediaSource(videoSource, subtitleSource);
// Preparo el reproductor con los subtitulos y el video
player.prepare(mergedSource);
} else // Si no tiene subtitulos preparo solo el video
player.prepare(videoSource);
}
}
示例4: getMediaSourceSubtitle
import com.google.android.exoplayer2.source.SingleSampleMediaSource; //导入依赖的package包/类
public MediaSource getMediaSourceSubtitle(){
return new SingleSampleMediaSource(this.getSubtitleUri(),this.getDataSourceFactory(), this.getFormat(), C.TIME_UNSET);
}