1*30877f79SAndroid Build Coastguard Worker# ExoPlayer Flac module 2*30877f79SAndroid Build Coastguard Worker 3*30877f79SAndroid Build Coastguard WorkerThe Flac module provides `FlacExtractor` and `LibflacAudioRenderer`, which use 4*30877f79SAndroid Build Coastguard WorkerlibFLAC (the Flac decoding library) to extract and decode FLAC audio. 5*30877f79SAndroid Build Coastguard Worker 6*30877f79SAndroid Build Coastguard Worker## License note 7*30877f79SAndroid Build Coastguard Worker 8*30877f79SAndroid Build Coastguard WorkerPlease note that whilst the code in this repository is licensed under 9*30877f79SAndroid Build Coastguard Worker[Apache 2.0][], using this module also requires building and including one or 10*30877f79SAndroid Build Coastguard Workermore external libraries as described below. These are licensed separately. 11*30877f79SAndroid Build Coastguard Worker 12*30877f79SAndroid Build Coastguard Worker[Apache 2.0]: https://github.com/google/ExoPlayer/blob/release-v2/LICENSE 13*30877f79SAndroid Build Coastguard Worker 14*30877f79SAndroid Build Coastguard Worker## Build instructions (Linux, macOS) 15*30877f79SAndroid Build Coastguard Worker 16*30877f79SAndroid Build Coastguard WorkerTo use the module you need to clone this GitHub project and depend on its 17*30877f79SAndroid Build Coastguard Workermodules locally. Instructions for doing this can be found in the 18*30877f79SAndroid Build Coastguard Worker[top level README][]. 19*30877f79SAndroid Build Coastguard Worker 20*30877f79SAndroid Build Coastguard WorkerIn addition, it's necessary to build the module's native components as follows: 21*30877f79SAndroid Build Coastguard Worker 22*30877f79SAndroid Build Coastguard Worker* Set the following environment variables: 23*30877f79SAndroid Build Coastguard Worker 24*30877f79SAndroid Build Coastguard Worker``` 25*30877f79SAndroid Build Coastguard Workercd "<path to project checkout>" 26*30877f79SAndroid Build Coastguard WorkerFLAC_MODULE_PATH="$(pwd)/extensions/flac/src/main" 27*30877f79SAndroid Build Coastguard Worker``` 28*30877f79SAndroid Build Coastguard Worker 29*30877f79SAndroid Build Coastguard Worker* Download the [Android NDK][] and set its location in an environment variable. 30*30877f79SAndroid Build Coastguard Worker This build configuration has been tested on NDK r21. 31*30877f79SAndroid Build Coastguard Worker 32*30877f79SAndroid Build Coastguard Worker``` 33*30877f79SAndroid Build Coastguard WorkerNDK_PATH="<path to Android NDK>" 34*30877f79SAndroid Build Coastguard Worker``` 35*30877f79SAndroid Build Coastguard Worker 36*30877f79SAndroid Build Coastguard Worker* Download and extract flac-1.3.2 as "${FLAC_MODULE_PATH}/jni/flac" folder: 37*30877f79SAndroid Build Coastguard Worker 38*30877f79SAndroid Build Coastguard Worker``` 39*30877f79SAndroid Build Coastguard Workercd "${FLAC_MODULE_PATH}/jni" && \ 40*30877f79SAndroid Build Coastguard Workercurl https://ftp.osuosl.org/pub/xiph/releases/flac/flac-1.3.2.tar.xz | tar xJ && \ 41*30877f79SAndroid Build Coastguard Workermv flac-1.3.2 flac 42*30877f79SAndroid Build Coastguard Worker``` 43*30877f79SAndroid Build Coastguard Worker 44*30877f79SAndroid Build Coastguard Worker* Build the JNI native libraries from the command line: 45*30877f79SAndroid Build Coastguard Worker 46*30877f79SAndroid Build Coastguard Worker``` 47*30877f79SAndroid Build Coastguard Workercd "${FLAC_MODULE_PATH}"/jni && \ 48*30877f79SAndroid Build Coastguard Worker${NDK_PATH}/ndk-build APP_ABI=all -j4 49*30877f79SAndroid Build Coastguard Worker``` 50*30877f79SAndroid Build Coastguard Worker 51*30877f79SAndroid Build Coastguard Worker[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md 52*30877f79SAndroid Build Coastguard Worker[Android NDK]: https://developer.android.com/tools/sdk/ndk/index.html 53*30877f79SAndroid Build Coastguard Worker 54*30877f79SAndroid Build Coastguard Worker## Build instructions (Windows) 55*30877f79SAndroid Build Coastguard Worker 56*30877f79SAndroid Build Coastguard WorkerWe do not provide support for building this module on Windows, however it should 57*30877f79SAndroid Build Coastguard Workerbe possible to follow the Linux instructions in [Windows PowerShell][]. 58*30877f79SAndroid Build Coastguard Worker 59*30877f79SAndroid Build Coastguard Worker[Windows PowerShell]: https://docs.microsoft.com/en-us/powershell/scripting/getting-started/getting-started-with-windows-powershell 60*30877f79SAndroid Build Coastguard Worker 61*30877f79SAndroid Build Coastguard Worker## Using the module 62*30877f79SAndroid Build Coastguard Worker 63*30877f79SAndroid Build Coastguard WorkerOnce you've followed the instructions above to check out, build and depend on 64*30877f79SAndroid Build Coastguard Workerthe module, the next step is to tell ExoPlayer to use the extractor and/or 65*30877f79SAndroid Build Coastguard Workerrenderer. 66*30877f79SAndroid Build Coastguard Worker 67*30877f79SAndroid Build Coastguard Worker### Using `FlacExtractor` 68*30877f79SAndroid Build Coastguard Worker 69*30877f79SAndroid Build Coastguard Worker`FlacExtractor` is used via `ProgressiveMediaSource`. If you're using 70*30877f79SAndroid Build Coastguard Worker`DefaultExtractorsFactory`, `FlacExtractor` will automatically be used to read 71*30877f79SAndroid Build Coastguard Worker`.flac` files. If you're not using `DefaultExtractorsFactory`, return a 72*30877f79SAndroid Build Coastguard Worker`FlacExtractor` from your `ExtractorsFactory.createExtractors` implementation. 73*30877f79SAndroid Build Coastguard Worker 74*30877f79SAndroid Build Coastguard Worker### Using `LibflacAudioRenderer` 75*30877f79SAndroid Build Coastguard Worker 76*30877f79SAndroid Build Coastguard Worker* If you're passing a `DefaultRenderersFactory` to `ExoPlayer.Builder`, you 77*30877f79SAndroid Build Coastguard Worker can enable using the module by setting the `extensionRendererMode` parameter 78*30877f79SAndroid Build Coastguard Worker of the `DefaultRenderersFactory` constructor to 79*30877f79SAndroid Build Coastguard Worker `EXTENSION_RENDERER_MODE_ON`. This will use `LibflacAudioRenderer` for 80*30877f79SAndroid Build Coastguard Worker playback if `MediaCodecAudioRenderer` doesn't support the input format. Pass 81*30877f79SAndroid Build Coastguard Worker `EXTENSION_RENDERER_MODE_PREFER` to give `LibflacAudioRenderer` priority 82*30877f79SAndroid Build Coastguard Worker over `MediaCodecAudioRenderer`. 83*30877f79SAndroid Build Coastguard Worker* If you've subclassed `DefaultRenderersFactory`, add a `LibflacAudioRenderer` 84*30877f79SAndroid Build Coastguard Worker to the output list in `buildAudioRenderers`. ExoPlayer will use the first 85*30877f79SAndroid Build Coastguard Worker `Renderer` in the list that supports the input media format. 86*30877f79SAndroid Build Coastguard Worker* If you've implemented your own `RenderersFactory`, return a 87*30877f79SAndroid Build Coastguard Worker `LibflacAudioRenderer` instance from `createRenderers`. ExoPlayer will use 88*30877f79SAndroid Build Coastguard Worker the first `Renderer` in the returned array that supports the input media 89*30877f79SAndroid Build Coastguard Worker format. 90*30877f79SAndroid Build Coastguard Worker* If you're using `ExoPlayer.Builder`, pass a `LibflacAudioRenderer` in the 91*30877f79SAndroid Build Coastguard Worker array of `Renderer`s. ExoPlayer will use the first `Renderer` in the list 92*30877f79SAndroid Build Coastguard Worker that supports the input media format. 93*30877f79SAndroid Build Coastguard Worker 94*30877f79SAndroid Build Coastguard WorkerNote: These instructions assume you're using `DefaultTrackSelector`. If you have 95*30877f79SAndroid Build Coastguard Workera custom track selector the choice of `Renderer` is up to your implementation, 96*30877f79SAndroid Build Coastguard Workerso you need to make sure you are passing an `LibflacAudioRenderer` to the 97*30877f79SAndroid Build Coastguard Workerplayer, then implement your own logic to use the renderer for a given track. 98*30877f79SAndroid Build Coastguard Worker 99*30877f79SAndroid Build Coastguard Worker## Using the module in the demo application 100*30877f79SAndroid Build Coastguard Worker 101*30877f79SAndroid Build Coastguard WorkerTo try out playback using the module in the [demo application][], see 102*30877f79SAndroid Build Coastguard Worker[enabling extension decoders][]. 103*30877f79SAndroid Build Coastguard Worker 104*30877f79SAndroid Build Coastguard Worker[demo application]: https://exoplayer.dev/demo-application.html 105*30877f79SAndroid Build Coastguard Worker[enabling extension decoders]: https://exoplayer.dev/demo-application.html#enabling-extension-decoders 106*30877f79SAndroid Build Coastguard Worker 107*30877f79SAndroid Build Coastguard Worker## Links 108*30877f79SAndroid Build Coastguard Worker 109*30877f79SAndroid Build Coastguard Worker* [Javadoc][] 110*30877f79SAndroid Build Coastguard Worker 111*30877f79SAndroid Build Coastguard Worker[Javadoc]: https://exoplayer.dev/doc/reference/index.html 112