From cda61f1fe44c32a7d9055831839d3146cb07cc73 Mon Sep 17 00:00:00 2001 From: Rafal Date: Mon, 30 Apr 2018 12:57:03 +0200 Subject: [PATCH] Added empty state, fixed bugs --- gradle/wrapper/gradle-wrapper.properties | 3 ++- .../coneey/rxaudiomanager/mediaListener/MediaState.kt | 2 +- .../rxaudiomanager/mediaListener/MediaStateResolver.kt | 10 +++++++--- .../serviceMediaManager/PlayerService.kt | 2 +- .../simpleMediaManager/InternalMediaPlayer.kt | 3 ++- .../rxaudiomanager/simpleMediaManager/MediaManager.kt | 2 +- .../simpleMediaManager/MediaServiceCommandEmitter.kt | 4 ++-- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 933b647..6f3658d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Mon Apr 30 12:56:36 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/mediaListener/MediaState.kt b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/mediaListener/MediaState.kt index c9145be..e5d40ed 100644 --- a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/mediaListener/MediaState.kt +++ b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/mediaListener/MediaState.kt @@ -1,5 +1,5 @@ package github.com.coneey.rxaudiomanager.mediaListener enum class MediaState { - PREPARING, RUNNING, STOPPED, PAUSED, ERROR, COMPLETED + EMPTY, PREPARING, RUNNING, STOPPED, PAUSED, ERROR, COMPLETED } \ No newline at end of file diff --git a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/mediaListener/MediaStateResolver.kt b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/mediaListener/MediaStateResolver.kt index 808d40a..0f15bf0 100644 --- a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/mediaListener/MediaStateResolver.kt +++ b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/mediaListener/MediaStateResolver.kt @@ -33,7 +33,7 @@ class MediaStateResolver(private val player: MediaPlayer) : MediaPlayer.OnPrepar private val infoFunction4 = Function4 { t1: MediaState, t2: Percent, t3: Second, t4: Second -> MediaInfo(t1, t2, t3, t3 / 1000, t4) } val infoSubject: Observable = Observable.combineLatest( - stateSubject.startWith(MediaState.PREPARING), bufferSubject.startWith(0), + stateSubject.startWith(MediaState.EMPTY), bufferSubject.startWith(0), positionSubject.startWith(0), durationSubject.startWith(0), infoFunction4) fun initialize(): Observable { @@ -56,6 +56,7 @@ class MediaStateResolver(private val player: MediaPlayer) : MediaPlayer.OnPrepar override fun onPrepared(mp: MediaPlayer) { + preapred = true onPreparedRunnables.forEach { it.invoke(mp) } onPreparedRunnables.clear() } @@ -141,6 +142,7 @@ class MediaStateResolver(private val player: MediaPlayer) : MediaPlayer.OnPrepar stateSubject.onNext(MediaState.STOPPED) } } + fun start() { if (!player.isPlaying) { postWhenPrepared { @@ -159,7 +161,9 @@ class MediaStateResolver(private val player: MediaPlayer) : MediaPlayer.OnPrepar stateSubject.onNext(preparing) } - - + fun reset() { + player.reset() + preapred = false + } } \ No newline at end of file diff --git a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/serviceMediaManager/PlayerService.kt b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/serviceMediaManager/PlayerService.kt index 43c9642..4f819d5 100644 --- a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/serviceMediaManager/PlayerService.kt +++ b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/serviceMediaManager/PlayerService.kt @@ -35,7 +35,7 @@ class PlayerService : LifecycleService() { is ServiceCommand.Pause -> mediaManager.pause() is ServiceCommand.Resume -> mediaManager.resume() is ServiceCommand.SeekTo -> mediaManager.seekTo(it.millisecond) - is ServiceCommand.Restart -> mediaManager.restart() + is ServiceCommand.Restart -> mediaManager.reset() is ServiceCommand.Start -> mediaManager.start() } diff --git a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/InternalMediaPlayer.kt b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/InternalMediaPlayer.kt index 2040ff4..2967088 100644 --- a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/InternalMediaPlayer.kt +++ b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/InternalMediaPlayer.kt @@ -105,7 +105,8 @@ open class InternalMediaPlayer(val player: MediaPlayer, val context: Context, mediaDisposable?.dispose() } - override fun restart() { + override fun reset() { + resolver.reset() val audioAttr = currentAudioAttributes val datasource = currentDataSource if (datasource != null && audioAttr != null) { diff --git a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/MediaManager.kt b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/MediaManager.kt index 51a2700..52ab0bd 100644 --- a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/MediaManager.kt +++ b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/MediaManager.kt @@ -17,7 +17,7 @@ interface MediaManager { fun start() fun resume() fun stop() - fun restart() + fun reset() fun getMediaInfoObservable(): Observable } \ No newline at end of file diff --git a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/MediaServiceCommandEmitter.kt b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/MediaServiceCommandEmitter.kt index 27c53d0..2457fa9 100644 --- a/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/MediaServiceCommandEmitter.kt +++ b/rxaudiomanager/src/main/java/github/com/coneey/rxaudiomanager/simpleMediaManager/MediaServiceCommandEmitter.kt @@ -8,7 +8,7 @@ import io.reactivex.Observable import io.reactivex.subjects.BehaviorSubject import io.reactivex.subjects.Subject -object MediaServiceCommandEmitter : MediaManager { +internal object MediaServiceCommandEmitter : MediaManager { val mediaInfoSubject: Subject = BehaviorSubject.create() val commandSubject: Subject = BehaviorSubject.create() @@ -53,7 +53,7 @@ object MediaServiceCommandEmitter : MediaManager { commandSubject.onNext(ServiceCommand.Stop) } - override fun restart() { + override fun reset() { commandSubject.onNext(ServiceCommand.Restart) }