使用ExoPlayer播放视频流无法在TextureView中正确显示

时间:2018-08-23 08:42:47

标签: android exoplayer

我有一个TextureView:

<TextureView
        android:id="@+id/texture_view"
        android:layout_width="298dp"
        android:layout_height="205dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="37dp"
        android:layout_marginTop="31dp"
        android:focusable="true"
        app:resize_mode="fill"/>

然后,我为流视频创建ExoPlayer并将其设置到我的TextureView中:

private static final String TAG = "MainActivity";
    private TextureView simpleExoPlayerView;
    private SimpleExoPlayer player;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

// 1. Create a default TrackSelector
        BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
        TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

// 2. Create a default LoadControl
        LoadControl loadControl = new DefaultLoadControl();

// 3. Create the player
            player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
            simpleExoPlayerView = new TextureView(this);
            simpleExoPlayerView = (TextureView) findViewById(R.id.texture_view);

//Set media controller

// Bind the player to the view.
            player.setVideoTextureView(simpleExoPlayerView);
            Uri mp4VideoUri = Uri.parse("http://mediaserver01.heartscreation.co.jp/Dash2/John_Test/John_Test.mpd");

//Measures bandwidth during playback. Can be null if not required.
            DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter();
//Produces DataSource instances through which media data is loaded.
            DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), bandwidthMeterA);
            DashChunkSource.Factory dashChunkSourceFactory =
                    new DefaultDashChunkSource.Factory(dataSourceFactory);
//Produces Extractor instances for parsing the media data.
            ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();

            MediaSource videoSource = new DashMediaSource(mp4VideoUri, dataSourceFactory, dashChunkSourceFactory, null, null);
            final LoopingMediaSource loopingSource = new LoopingMediaSource(videoSource);

// Prepare the player with the source.
            player.prepare(loopingSource);
            player.setPlayWhenReady(true);

我希望它将在TextureView中正常显示,但事实并非如此,这是我的结果: https://ibb.co/dpUWCe

哪里错了,如何解决?非常感谢。

0 个答案:

没有答案