Added null checks, moved MediaPlayer to its own Koin module
This commit is contained in:
parent
bbe9f39300
commit
bd77c2a851
|
@ -47,7 +47,6 @@ public class Downloader
|
|||
private ScheduledExecutorService executorService;
|
||||
private long revision;
|
||||
|
||||
|
||||
public Downloader(Context context, ShufflePlayBuffer shufflePlayBuffer, ExternalStorageMonitor externalStorageMonitor,
|
||||
LocalMediaPlayer localMediaPlayer)
|
||||
{
|
||||
|
@ -150,6 +149,7 @@ public class Downloader
|
|||
if (start == -1) start = 0;
|
||||
|
||||
int i = start;
|
||||
// Check all DownloadFiles on the playlist
|
||||
do
|
||||
{
|
||||
DownloadFile downloadFile = downloadList.get(i);
|
||||
|
@ -162,6 +162,7 @@ public class Downloader
|
|||
cleanupCandidates.add(currentDownloading);
|
||||
if (i == (start + 1))
|
||||
{
|
||||
// The next file on the playlist is currently downloading
|
||||
localMediaPlayer.setNextPlayerState(DOWNLOADING);
|
||||
}
|
||||
break;
|
||||
|
@ -176,6 +177,7 @@ public class Downloader
|
|||
} while (i != start);
|
||||
}
|
||||
|
||||
// If the downloadList contains no work, check the backgroundDownloadList
|
||||
if ((preloaded + 1 == n || preloaded >= Util.getPreloadCount(context) || downloadList.isEmpty()) && !backgroundDownloadList.isEmpty())
|
||||
{
|
||||
for (int i = 0; i < backgroundDownloadList.size(); i++)
|
||||
|
|
|
@ -293,6 +293,8 @@ public class LocalMediaPlayer
|
|||
updateRemoteControl();
|
||||
}
|
||||
|
||||
if (onPlayerStateChanged != null)
|
||||
{
|
||||
Handler mainHandler = new Handler(context.getMainLooper());
|
||||
Runnable myRunnable = new Runnable() {
|
||||
@Override
|
||||
|
@ -301,6 +303,7 @@ public class LocalMediaPlayer
|
|||
}
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}
|
||||
|
||||
if (playerState == STARTED && positionCache == null)
|
||||
{
|
||||
|
@ -321,6 +324,8 @@ public class LocalMediaPlayer
|
|||
this.currentPlaying = currentPlaying;
|
||||
updateRemoteControl();
|
||||
|
||||
if (onCurrentPlayingChanged != null)
|
||||
{
|
||||
Handler mainHandler = new Handler(context.getMainLooper());
|
||||
Runnable myRunnable = new Runnable() {
|
||||
@Override
|
||||
|
@ -330,6 +335,7 @@ public class LocalMediaPlayer
|
|||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void setNextPlaying(DownloadFile nextToPlay)
|
||||
{
|
||||
|
@ -398,6 +404,7 @@ public class LocalMediaPlayer
|
|||
setPlayerState(PlayerState.STARTED);
|
||||
setupHandlers(currentPlaying, false);
|
||||
|
||||
if (onNextSongRequested != null) {
|
||||
Handler mainHandler = new Handler(context.getMainLooper());
|
||||
Runnable myRunnable = new Runnable() {
|
||||
@Override
|
||||
|
@ -406,6 +413,7 @@ public class LocalMediaPlayer
|
|||
}
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}
|
||||
|
||||
// Proxy should not be being used here since the next player was already setup to play
|
||||
if (proxy != null)
|
||||
|
@ -726,6 +734,7 @@ public class LocalMediaPlayer
|
|||
}
|
||||
}
|
||||
|
||||
if (onPrepared != null) {
|
||||
Handler mainHandler = new Handler(context.getMainLooper());
|
||||
Runnable myRunnable = new Runnable() {
|
||||
@Override
|
||||
|
@ -735,6 +744,7 @@ public class LocalMediaPlayer
|
|||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setupHandlers(downloadFile, partial);
|
||||
|
@ -861,6 +871,8 @@ public class LocalMediaPlayer
|
|||
playNext();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (onSongCompleted != null)
|
||||
{
|
||||
Handler mainHandler = new Handler(context.getMainLooper());
|
||||
Runnable myRunnable = new Runnable() {
|
||||
|
@ -871,6 +883,7 @@ public class LocalMediaPlayer
|
|||
};
|
||||
mainHandler.post(myRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ public class StreamProxy implements Runnable
|
|||
public void run()
|
||||
{
|
||||
Log.i(TAG, "Streaming song in background");
|
||||
DownloadFile downloadFile = currentPlaying.get();
|
||||
DownloadFile downloadFile = currentPlaying == null? null : currentPlaying.get();
|
||||
MusicDirectory.Entry song = downloadFile.getSong();
|
||||
long fileSize = downloadFile.getBitRate() * ((song.getDuration() != null) ? song.getDuration() : 0) * 1000 / 8;
|
||||
Log.i(TAG, String.format("Streaming fileSize: %d", fileSize));
|
||||
|
|
|
@ -2,12 +2,7 @@ package org.moire.ultrasonic.app
|
|||
|
||||
import androidx.multidex.MultiDexApplication
|
||||
import org.koin.android.ext.android.startKoin
|
||||
import org.moire.ultrasonic.di.DiProperties
|
||||
import org.moire.ultrasonic.di.appPermanentStorage
|
||||
import org.moire.ultrasonic.di.baseNetworkModule
|
||||
import org.moire.ultrasonic.di.directoriesModule
|
||||
import org.moire.ultrasonic.di.featureFlagsModule
|
||||
import org.moire.ultrasonic.di.musicServiceModule
|
||||
import org.moire.ultrasonic.di.*
|
||||
|
||||
class UApp : MultiDexApplication() {
|
||||
override fun onCreate() {
|
||||
|
@ -20,7 +15,8 @@ class UApp : MultiDexApplication() {
|
|||
appPermanentStorage,
|
||||
baseNetworkModule,
|
||||
featureFlagsModule,
|
||||
musicServiceModule
|
||||
musicServiceModule,
|
||||
mediaPlayerModule
|
||||
),
|
||||
extraProperties = mapOf(
|
||||
DiProperties.APP_CONTEXT to applicationContext
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package org.moire.ultrasonic.di
|
||||
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.dsl.module.module
|
||||
import org.moire.ultrasonic.service.*
|
||||
import org.moire.ultrasonic.util.ShufflePlayBuffer
|
||||
|
||||
val mediaPlayerModule = module {
|
||||
single<MediaPlayerController> { MediaPlayerControllerImpl(androidContext(), get(), get(), get(), get(), get()) }
|
||||
single { JukeboxMediaPlayer(androidContext(), get()) }
|
||||
single { MediaPlayerLifecycleSupport(androidContext(), get(), get(), get()) }
|
||||
single { DownloadQueueSerializer(androidContext()) }
|
||||
single { ExternalStorageMonitor(androidContext()) }
|
||||
single { ShufflePlayBuffer(androidContext()) }
|
||||
single { Downloader(androidContext(), get(), get(), get()) }
|
||||
single { LocalMediaPlayer(androidContext()) }
|
||||
|
||||
// TODO: Ideally this can be cleaned up when all circular references are removed.
|
||||
single { MediaPlayerControllerImpl(androidContext(), get(), get(), get(), get(), get()) }
|
||||
}
|
|
@ -112,16 +112,4 @@ val musicServiceModule = module(MUSIC_SERVICE_CONTEXT) {
|
|||
}
|
||||
|
||||
single { SubsonicImageLoader(getProperty(DiProperties.APP_CONTEXT), get()) }
|
||||
|
||||
single<MediaPlayerController> { MediaPlayerControllerImpl(androidContext(), get(), get(), get(), get(), get()) }
|
||||
single { JukeboxMediaPlayer(androidContext(), get()) }
|
||||
single { MediaPlayerLifecycleSupport(androidContext(), get(), get(), get()) }
|
||||
single { DownloadQueueSerializer(androidContext()) }
|
||||
single { ExternalStorageMonitor(androidContext()) }
|
||||
single { ShufflePlayBuffer(androidContext()) }
|
||||
single { Downloader(androidContext(), get(), get(), get()) }
|
||||
single { LocalMediaPlayer(androidContext()) }
|
||||
|
||||
// TODO: Ideally this can be cleaned up when all circular references are removed.
|
||||
single { MediaPlayerControllerImpl(androidContext(), get(), get(), get(), get(), get()) }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue