Android stream over ExoPlayer

微笑、不失礼 提交于 2019-12-06 09:20:46
    FrameworkSampleSource source = new FrameworkSampleSource(App.getContext(), track.Uri, null, 1);
    TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(source, null, true);
    exoPlayer.prepare(audioRenderer);

Hope this short example will help

Gujarat Santana

If you're looking for a simple implementation, I've created simple apps from ExoPlayer Demo that are easier to read.

The Link : https://github.com/Gujarats/AndroidVideoPlayer/tree/master/app/src/main
You need to see these files for better understanding :

  • Layout : test_player.xml
  • TestPlayerActivity
  • TestPlayerController

I've tested it and played .mp4 files over HTTP.

I had to replace MediaPlayer with ExoPlayer today for a radio streaming app. I made a post about it in case it would help anyone. It uses MediaCodecAudioTrackRenderer with ExtractorSampleSource (since FrameworkSampleSource is deprecated).

            Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
            String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
            DataSource dataSource = new DefaultUriDataSource(context, null, userAgent);
            ExtractorSampleSource sampleSource = new ExtractorSampleSource(
                    radioUri, dataSource, allocator, BUFFER_SEGMENT_SIZE * BUFFER_SEGMENT_COUNT);
            audioRenderer = new MediaCodecAudioTrackRenderer(
                    sampleSource);

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