com.google.android.exoplayer2.source.UnrecognizedInputFormatException:

巧了我就是萌 提交于 2019-12-13 03:55:57

问题


I need to reproduce a live show with exoplayer in format .mpd.

But i get this error:

com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor) could read the stream.

I don't know why!

This is my code:

public class MainActivity extends AppCompatActivity {

    SimpleExoPlayer exoPlayer;

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



        exoPlayerView = (SimpleExoPlayerView) findViewById(R.id.exo_player_view);
        exoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);

        try {


            BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
            TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
            exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);

            Uri videoURI = Uri.parse("blablabla/manifest.mpd");

            DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("exoplayer_video");
            ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
            MediaSource mediaSource = new ExtractorMediaSource(videoURI, dataSourceFactory, extractorsFactory, null, null);

            exoPlayerView.setPlayer(exoPlayer);
            exoPlayer.prepare(mediaSource);
            exoPlayer.setPlayWhenReady(true);
        }catch (Exception e){
            Log.e("MainAcvtivity"," exoplayer error "+ e.toString());
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        exoPlayer.stop();
    }
    @Override
    protected void onPause() {
        super.onPause();
        exoPlayer.stop();
    }
}

回答1:


.mpd is commonly pointing to a DASH manifest which is an adaptive format. The manifest lists media representations of different qualities with which the player can adapt to given bandwidth conditions.

To play a DASH manifest (.mpd) you create a DASH specific media source.

Use a DashMediaSource instead of an ExtractorsMediaSource:

// meter bandwidth with media files (video/audio)
DefaultHttpDataSourceFactory mediaDataSourceFactory = new DefaultHttpDataSourceFactory(
    Util.getUserAgent(this, "stackoverflow"), BANDWIDTH_METER);
// do not meter bandwidth for manifest loading
DefaultHttpDataSourceFactory manifestDataSourceFactory = new DefaultHttpDataSourceFactory(
    Util.getUserAgent(this, "stackoverflow"));
// create the media source for DASH
MediaSource mediaSource = new DashMediaSource.Factory(
    new DefaultDashChunkSource.Factory(mediaDataSourceFactory),
    manifestDataSourceFactory)
    .createMediaSource(uri, null, null);

// prepare the player
player.setPlayWhenReady(true);
player.prepare(mediaSource);


来源:https://stackoverflow.com/questions/47702209/com-google-android-exoplayer2-source-unrecognizedinputformatexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!