使Exoplayer正常工作时遇到问题。我设法从网址加载视频。但它只播放音频。所以我做错了。
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer exoPlayer = ExoPlayerFactory.newSimpleInstance(simpleExoPlayerView.getContext(), trackSelector, loadControl); Uri mp4VideoUri = Uri.parse(videoUri); DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("ExoPlayerDemo"); ExtractorsFactory extractor = new DefaultExtractorsFactory(); MediaSource videoSource = new ExtractorMediaSource(mp4VideoUri, dataSourceFactory, extractor, null, null); exoPlayer.prepare(videoSource); exoPlayer.setPlayWhenReady(true);
这就是我只能播放音频的方式。不知道我应该改变什么。
您似乎错过了将播放器绑定到播放器视图的念头
附加播放器以查看
ExoPlayer库提供了一个SimpleExoPlayerView,它封装了一个PlaybackControlView和一个在其上呈现视频的Surface。SimpleExoPlayerView可以包含在应用程序的布局xml中。将播放器绑定到视图很简单:
// Bind the player to the view. simpleExoPlayerView.setPlayer(player);
如果您需要对播放器控件和在其上渲染视频的Surface进行细粒度控制,则可以分别使用SimpleExoPlayer的setVideoSurfaceView,setVideoTextureView,setVideoSurfaceHolder和setVideoSurface方法直接设置播放器的目标SurfaceView,TextureView,SurfaceHolder或Surface。您可以将PlaybackControlView用作独立组件,也可以实现自己的播放控件,这些控件直接与播放器进行交互。setTextOutput和setId3Output可用于在播放期间接收字幕和ID3元数据输出。