Clarified that it is using caller thread. not main thread
This commit is contained in:
parent
156a20734a
commit
5745da75a6
|
@ -63,16 +63,16 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
||||||
/**
|
/**
|
||||||
* All ExoPlayer methods must be executed on the same thread.
|
* All ExoPlayer methods must be executed on the same thread.
|
||||||
* We use the main application thread. This class allows to
|
* We use the main application thread. This class allows to
|
||||||
* "fake" an executor that just calls the method instead of
|
* "fake" an executor that just calls the methods on the
|
||||||
* submitting to another thread. Other players are still
|
* calling thread instead of submitting to an executor.
|
||||||
* executed in a background thread.
|
* Other players are still executed in a background thread.
|
||||||
*/
|
*/
|
||||||
private class PlayerExecutor {
|
private class PlayerExecutor {
|
||||||
private boolean useMainThread = true;
|
private boolean useCallerThread = true;
|
||||||
private ThreadPoolExecutor threadPool;
|
private ThreadPoolExecutor threadPool;
|
||||||
|
|
||||||
public Future<?> submit(Runnable r) {
|
public Future<?> submit(Runnable r) {
|
||||||
if (useMainThread) {
|
if (useCallerThread) {
|
||||||
r.run();
|
r.run();
|
||||||
return new FutureTask<Void>(() -> {}, null);
|
return new FutureTask<Void>(() -> {}, null);
|
||||||
} else {
|
} else {
|
||||||
|
@ -132,7 +132,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
||||||
@Override
|
@Override
|
||||||
public void playMediaObject(@NonNull final Playable playable, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) {
|
public void playMediaObject(@NonNull final Playable playable, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) {
|
||||||
Log.d(TAG, "playMediaObject(...)");
|
Log.d(TAG, "playMediaObject(...)");
|
||||||
executor.useMainThread = UserPreferences.useExoplayer();
|
executor.useCallerThread = UserPreferences.useExoplayer();
|
||||||
executor.submit(() -> {
|
executor.submit(() -> {
|
||||||
playerLock.lock();
|
playerLock.lock();
|
||||||
try {
|
try {
|
||||||
|
@ -400,7 +400,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void reinit() {
|
public void reinit() {
|
||||||
executor.useMainThread = UserPreferences.useExoplayer();
|
executor.useCallerThread = UserPreferences.useExoplayer();
|
||||||
executor.submit(() -> {
|
executor.submit(() -> {
|
||||||
playerLock.lock();
|
playerLock.lock();
|
||||||
Log.d(TAG, "reinit()");
|
Log.d(TAG, "reinit()");
|
||||||
|
@ -850,7 +850,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
||||||
@Override
|
@Override
|
||||||
protected Future<?> endPlayback(final boolean hasEnded, final boolean wasSkipped,
|
protected Future<?> endPlayback(final boolean hasEnded, final boolean wasSkipped,
|
||||||
final boolean shouldContinue, final boolean toStoppedState) {
|
final boolean shouldContinue, final boolean toStoppedState) {
|
||||||
executor.useMainThread = UserPreferences.useExoplayer();
|
executor.useCallerThread = UserPreferences.useExoplayer();
|
||||||
return executor.submit(() -> {
|
return executor.submit(() -> {
|
||||||
playerLock.lock();
|
playerLock.lock();
|
||||||
releaseWifiLockIfNecessary();
|
releaseWifiLockIfNecessary();
|
||||||
|
@ -1057,7 +1057,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
||||||
playerLock.unlock();
|
playerLock.unlock();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (executor.useMainThread) {
|
if (executor.useCallerThread) {
|
||||||
r.run();
|
r.run();
|
||||||
} else {
|
} else {
|
||||||
new Thread(r).start();
|
new Thread(r).start();
|
||||||
|
|
Loading…
Reference in New Issue