0

Issue description

I'm trying to implement Exoplayer to play background music in loop and speech sounds at the same time that are played on click events. I can't add silence at the end of the file because I play them in raw to make a sentence like :

file one : "select"

file two : "a category"

That's why I can't have a silence gap between 2 files and there are about 1500 files in the app so I do that to save space.

At first I was with MediaPlayer but figured out that on certain phone (One plus A0001 ) I can't have 2 Mediaplayers working at the same time so I decided to go with Exoplayer. The 2 players are running in a service.

Background music are ogg files in the raw folder and works great.

I couldn't manage to play mp3 speech file from raw folder so i put them in asset folder and I manage to play them. The problem I am facing now is that at the end of every mp3 files is cut on some of my devices. The length of the cut depends of the device.

Did I made something wrong ?

Thanks for your help

This is my code for the soundPlayer

DefaultRenderersFactory renderersFactorySound = new DefaultRenderersFactory(this,null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
exoPlayerSound = ExoPlayerFactory.newSimpleInstance(renderersFactorySound, new DefaultTrackSelector(), new DefaultLoadControl());
exoPlayerSound.addListener(playerSoundEventListener);
exoPlayerSound.setVolume(1.0f);
exoPlayerSound.setRepeatMode(Player.REPEAT_MODE_OFF);

final AssetDataSource dataSource = new AssetDataSource(this);
DataSpec dataSpec = new DataSpec(Uri.parse("asset:///sounds/" + soundsToPlay.get(0) + ".mp3"));
try {
     dataSource.open(dataSpec);
} catch (AssetDataSource.AssetDataSourceException e) {
     e.printStackTrace();
}

DataSource.Factory factoryMusic = new DataSource.Factory() {
      @Override
      public DataSource createDataSource() {
              return dataSource;
      }
};
MediaSource audioSource = new ExtractorMediaSource(Uri.parse("asset:///sounds/" + soundsToPlay.get(0) + ".mp3"), factoryMusic, Mp3Extractor.FACTORY, null, null);
exoPlayerSound.prepare(audioSource);
exoPlayerSound.setPlayWhenReady(true);

This is my code for the musicPlayer

DefaultRenderersFactory renderersFactoryMusic = new DefaultRenderersFactory(this, null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
playerMusic = ExoPlayerFactory.newSimpleInstance(renderersFactoryMusic, new DefaultTrackSelector(), new DefaultLoadControl());
playerMusic.setVolume(0.4f);
playerMusic.setRepeatMode(Player.REPEAT_MODE_ONE);
DataSpec dataSpecMusic = new DataSpec(RawResourceDataSource.buildRawResourceUri(songId));
            final RawResourceDataSource rawResourceDataSourceMusic = new RawResourceDataSource(this);
            try {
                rawResourceDataSourceMusic.open(dataSpecMusic);
            } catch (RawResourceDataSource.RawResourceDataSourceException e) {
                e.printStackTrace();
            }

DataSource.Factory factoryMusic = new DataSource.Factory() {
     @Override
     public DataSource createDataSource() {
           return rawResourceDataSourceMusic;
     }
};

MediaSource audioSourceMusic = new ExtractorMediaSource(rawResourceDataSourceMusic.getUri(), factoryMusic, OggExtractor.FACTORY, null, null);
playerMusic.prepare(audioSourceMusic);
playerMusic.setPlayWhenReady(true);

Version of ExoPlayer being used

compile 'com.google.android.exoplayer:exoplayer-core:r2.5.4'

Device(s) and version(s) of Android being used

Devices with problem : Samung Galaxy note 3 SM-N9005 (Android v5.0) Acer Iconia B1-710 (Android v4.1.2)

Device without problem : One plus A0001 (Android v6.0.1) Samung Galaxy note 1 GT-N7000 (Android v4.1.2)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Abel Hamilton
  • 73
  • 1
  • 6
  • Don't think I see this anywhere in your code. If you don't want clipping then you need a listener to know when the file has finished. That should in theory fix the problem (I assume that version still has a completion listener anyway as it would be lame if it didn't) ...... of course you don't show this code: -> playerSoundEventListener <- lol ... if you're using that and not causing it to clip yourself (playing ONLY a single file clips at end) then its the device or the library. After that you may need to do what you don't want to do. Also a different format could have diff results? – CmosBattery Nov 11 '17 at 21:31
  • Possibly too something like file duration is handled incorrectly: https://github.com/google/ExoPlayer/issues/1110 .... hopefully something here helps! – CmosBattery Nov 11 '17 at 21:35
  • My playerSoundEventListener was just used for debug log. I've found it could be an issue with this library on few devices like here https://github.com/google/ExoPlayer/issues/3386. I decided to go with soundpool to play my short sounds for the moment. Thanks @CmosBattery for your answers. – Abel Hamilton Nov 13 '17 at 17:34

0 Answers0