Android stream over ExoPlayer

匆匆过客 提交于 2019-12-10 10:40:03

问题


I am trying to switch from MediaPlayer in favor of ExoPlayer but I can't find any updated demo how can I use it.I think they have removed the FrameworkSampleSource method. I downloaded the demo from Github but I can't find the implementation of player, I could find the Samples object where the URLs are added. I have a list of URL's that I want to be played.I am switching to ExoPlayer because it's smoother than MediaPlayer.I have read all StackOverflow topics about ExoPlayer but none of them are updated.

Can anyone give me an example how can implement it? Thank you.


回答1:


    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




回答2:


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.




回答3:


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);


来源:https://stackoverflow.com/questions/29830082/android-stream-over-exoplayer

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