Using the flac extension in Exoplayer in Android

2019-07-14 06:14发布

问题:

I'm trying to use ExoPlayer library with flac extension in my android application. And I faced with the following problems:

  • Not all files can be played (as far as I understand the problem with the files with a high bitrate);
  • not all devices able to play audio files in flac format (in the emulator and on the Samsung Galaxy S5 - played, but on Sony Xperia XA - something like a white noise instead of audio. All devices with Android 6.0. I tried to compile flac extensions with version 1.3.1 and 1.3.2)

How to get out of this situation?

My connection library:

settings.gradle

include ':app', ':playbacktests', ':testutils', ':library'
include ':extension-flac'

build.gradle

...
dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
      exclude group: 'com.android.support', module: 'support-annotations'
  })
  compile 'com.android.support:appcompat-v7:25.0.1'
  compile 'com.android.support:support-v4:25.0.1'
  //compile 'com.google.android.exoplayer:exoplayer:r2.1.1'
  compile project (':library')
  compile project (':extension-flac')
  testCompile 'junit:junit:4.12'
}

Sample code:

    DefaultBandwidthMeter bandwidthMeterAudio1 = new DefaultBandwidthMeter();
    DataSource.Factory dataSourceFactoryAudio = new DefaultDataSourceFactory(this.getActivity(),
            Util.getUserAgent(this.getActivity(), null), bandwidthMeterAudio1);

    ExtractorsFactory extractorsFactoryAudio = new DefaultExtractorsFactory();

    if (audioUri != null) { // audioUri - string array with paths of flac audio files
        if (audio_name != null){
            ArrayAdapter <String> adapter = new ArrayAdapter<String>(getActivity(),
                    R.layout.row_listview, audio_name);
            listViewMusic.setAdapter(adapter);
        }
        audioSource = new MediaSource[audioUri.length];

        for (int i = 0; i < audioUri.length; i++) {
            audioSource[i] = new ExtractorMediaSource(Uri.parse(audioUri[i]),
                    dataSourceFactoryAudio,extractorsFactoryAudio, null, null);
        }
        ConcatenatingMediaSource concatenatingMediaSourceAudio = new ConcatenatingMediaSource(audioSource);

        audioPlayer.prepare(concatenatingMediaSourceAudio);
    }