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)