Our APP is working fine with older versions of Kindle Fire HD having FireOS 5.1.x. APP is having problem only on Kindle HD 8 (10th Gen) with FireOS 7.3.1.4.
That issue is random sometime app works fine but other times APP do not behave good.
FireOS 7.3.1.4 is use android API LEVEL 28 (Android Pie)
We have music APP that has 3 Media Players, we are using Androids standard Media Player in our APP.
All of the 3 Media Players run Simultaneously and Tracks we run on each Media player have same duration.
We are doing all the processing in Background threads like playing music on all of the media players so there are 3 threads in total that are running in parallel.
The problem is on Kindle HD 8 (10th Gen) due to some glitch,track running on 1st Media Player overlaps with track on 2nd Media Player or go beyond track on the 2nd Media Player.
Overall what do I mean is that tracks on 3 of the media players goes out of sync even if they have same duration and they started at the same time.
One more thing songs start off without issues they are in sync in beginning , but after around 50 seconds they started to become out of sync.
That issue is happening on random times.
Again app is working fine on older version of Kindle Fire tablets and also on Samsung mobiles,the problem is only happening on Kindle HD 8 (10 Gen).
So, if anyone can help us in providing any solution on what is happening on new Kindle Fire HD? I will be very grateful for your help.
My guess is that background threads that are running the media player are having some problem at random times that makes media players out of sync. but I don't know how to rectify that behavior
Please Help us as we are stuck on this issue and our users can not use our APP on new Kindle Fire HD 8 tablet because of this. Thank you
Following is some of the code snippet of 3 Media Players we have
We create a new Media player and add a track into it. For loop in the code executed 3 times.
protected void initTracks(boolean high) {
this.mWavPlayers = new ArrayList<>();
HashMap<TrackType, String> map = null;
if (high) {
map = mPathHigh;
} else {
map = mPathLow;
}
try {
for (Map.Entry<TrackType, String> entry : map.entrySet()) {
MediaPlayer player = new MediaPlayer();
player.setDataSource(entry.getValue());
player.prepare();
mWavPlayers.add(new WavPlayerItem(entry.getValue(), entry.getKey(), player));
if (entry.getKey().equals(TrackType.BACKING_MUSIC)) {
mDuration = player.getDuration();
}
}
} catch (IOException e) {
Log.e(TAG, "Map exception", e);
}
}
This method create and starts the background thread, 3 background threads are created in for loop
protected void sendState(WavPlayerEvent.State state) {
CyclicBarrier barrier = new CyclicBarrier(mWavPlayers.size() + 1);
for (WavPlayerItem item : mWavPlayers) {
MediaPlayer player = (MediaPlayer) item.getPlayer();
new Thread(new SyncedStateRunnable(state, player, barrier, STATE.PLAYER)).start();
}
}
This method has a run method that start of the player in start()
private class SyncedStateRunnable<T> implements Runnable {
private WavPlayerEvent.State state;
private MediaPlayer player;
private NativeSuperpoweredRecorder recorder;
private CyclicBarrier cyclicBarrier;
private STATE entityState;
SyncedStateRunnable(WavPlayerEvent.State state, T entity, CyclicBarrier cyclicBarrier, STATE entityState) {
this.state = state;
this.cyclicBarrier = cyclicBarrier;
this.entityState = entityState;
switch (entityState) {
case PLAYER:
player = (MediaPlayer) entity;
break;
}
}
@Override
public void run() {
awaitBarrier();
switch (state) {
case PLAYING:
start();
break;
case STOP:
stop();
break;
case PAUSE:
pause();
break;
}
}
private void start() {
switch (entityState) {
case PLAYER:
try {
player.start();
Log.d(TAG, "player.start();");
} catch (IllegalStateException e) {
e.printStackTrace();
}
break;
}
}