在Android应用程序中使用ExoPlayer API进行视频播放
2023-08-23次
javaSimpleExoPlayer player = new SimpleExoPlayer.Builder(context).build();
// Create a DASH media source pointing to the URL of the DASH MPD file.
MediaSource mediaSource = new DashMediaSource.Factory(
new DefaultDataSourceFactory(context, "user-agent"))
.createMediaSource(Uri.parse("http://example.com/my-stream.mpd"));
// Prepare the player with the source.
player.setMediaSource(mediaSource);
player.prepare();
上述代码创建了一个SimpleExoPlayer实例,使用了一个DashMediaSource对象来指向视频流媒体。 DashMediaSource.Factory接受一个DefaultDataSourceFactory对象,它用于创建数据源。在这个例子中,我们使用了默认的数据源工厂。