How to use ExoPlayer

I want to use ExoPlayer in my application. Could you tell me what is the simplest example? I tried to make more likely https://github.com/google/ExoPlayer/ , but this is not easy for me. I tried to import libraryas a module, after which I got an error bintray-release.

+4
source share
2 answers

As stated in the main Readme.md , you can import ExoPlayer in the same way as for any other dependencies:

In application build.gradle> dependenciesadd:

compile 'com.google.android.exoplayer:exoplayer:rX.X.X'

r1.5.1 27 2015 . . .

+3

, ExoPlayer, . , , - Android ExoPlayer. , . .

http, , , - . v1.xx ExoPlayer, v1.5.11:

build.gradle(Module: app) "":

compile 'com.google.android.exoplayer:exoplayer:r1.5.11'

ExoPlayer.Listener:

...implements ExoPlayer.Listener

http:

    private static final int RENDERER_COUNT = 1; //since we want to render simple audio
    private static final int BUFFER_SEGMENT_SIZE = 64 * 1024; // for http mp3 audio stream use these values
    private static final int BUFFER_SEGMENT_COUNT = 256; // for http mp3 audio steam use these values
    private ExoPlayer exoPlayer;

// for http mp3 audio stream, use these values
    int minBufferMs = 1000;
    int minRebufferMs = 5000;

    // Prepare ExoPlayer
    exoPlayer = ExoPlayer.Factory.newInstance(RENDERER_COUNT, minBufferMs, minRebufferMs);

    // String with the url of the stream to play
    String stream_location = "http://audio_stream_url";        
    // Convert String URL to Uri
    Uri streamUri = Uri.parse(stream_location);

    // Settings for ExoPlayer
    Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
    String userAgent = Util.getUserAgent(ChicagoPoliceRadioService.this, "ExoPlayer_Test");
    DataSource dataSource = new DefaultUriDataSource(ChicagoPoliceRadioService.this, null, userAgent);
    ExtractorSampleSource sampleSource = new ExtractorSampleSource(
            streamUri, dataSource, allocator, BUFFER_SEGMENT_SIZE * BUFFER_SEGMENT_COUNT);
    MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource, MediaCodecSelector.DEFAULT);

    // Attach listener we implemented in this class to this ExoPlayer instance
    exoPlayer.addListener(this);

    // Prepare ExoPlayer
    exoPlayer.prepare(audioRenderer);

    // Set full volume
    exoPlayer.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_VOLUME, 1f);

    // Play!
    exoPlayer.setPlayWhenReady(true);

:

 @Override
 public void onPlayWhenReadyCommitted() {

    // No idea what would go here, I left it empty

}

// Called when ExoPlayer state changes
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {

    // If playbackState equals STATE_READY (4), that means ExoPlayer is set to
    // play and there are no errors
    if (playbackState == ExoPlayer.STATE_READY) {
        // ExoPlayer prepared and ready, no error
        // Put code here, same as "onPrepared()"
       }
}

// Called on ExoPlayer error
@Override
public void onPlayerError(ExoPlaybackException error) {
    // ExoPlayer error occurred
    // Put your error code here
}

, :

if (exoPlayer != null) {
                exoPlayer.stop();
                exoPlayer.release();
            }

. 100% ExoPlayer. . , 1.5.x ExoPlayer 2.0 , . , , , , Samsung, 30 .

+1

Source: https://habr.com/ru/post/1613322/


All Articles