Skip to content

Commit

Permalink
Added empty state, fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal committed Apr 30, 2018
1 parent 0543bb0 commit cda61f1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package git.luolix.top.coneey.rxaudiomanager.mediaListener

enum class MediaState {
PREPARING, RUNNING, STOPPED, PAUSED, ERROR, COMPLETED
EMPTY, PREPARING, RUNNING, STOPPED, PAUSED, ERROR, COMPLETED
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MediaInfo> = 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<MediaInfo> {
Expand All @@ -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()
}
Expand Down Expand Up @@ -141,6 +142,7 @@ class MediaStateResolver(private val player: MediaPlayer) : MediaPlayer.OnPrepar
stateSubject.onNext(MediaState.STOPPED)
}
}

fun start() {
if (!player.isPlaying) {
postWhenPrepared {
Expand All @@ -159,7 +161,9 @@ class MediaStateResolver(private val player: MediaPlayer) : MediaPlayer.OnPrepar
stateSubject.onNext(preparing)
}



fun reset() {
player.reset()
preapred = false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface MediaManager {
fun start()
fun resume()
fun stop()
fun restart()
fun reset()
fun getMediaInfoObservable(): Observable<MediaInfo>

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MediaInfo> = BehaviorSubject.create()
val commandSubject: Subject<ServiceCommand> = BehaviorSubject.create()
Expand Down Expand Up @@ -53,7 +53,7 @@ object MediaServiceCommandEmitter : MediaManager {
commandSubject.onNext(ServiceCommand.Stop)
}

override fun restart() {
override fun reset() {
commandSubject.onNext(ServiceCommand.Restart)
}

Expand Down

0 comments on commit cda61f1

Please sign in to comment.