Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #156 from readium/2.0.0-alpha.1
Browse files Browse the repository at this point in the history
2.0.0.alpha.1
  • Loading branch information
mickael-menu authored Aug 11, 2020
2 parents 6eb6108 + 33fb67a commit ac67a46
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 40 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ All notable changes to this project will be documented in this file.

**Warning:** Features marked as *experimental* may change or be removed in a future release without notice. Use with caution.

[unreleased]: https://github.com/readium/r2-navigator-kotlin/compare/master...HEAD
[1.2.0]: https://github.com/readium/r2-navigator-kotlin/compare/1.1.6...1.2.0

## [Unreleased]

## [1.2.0]
## [2.0.0-alpha.1]

### Added

Expand All @@ -35,3 +32,7 @@ All notable changes to this project will be documented in this file.
* [Crash when opening a publication with a space in its filename](https://github.com/readium/r2-navigator-kotlin/pull/136).
* [Jumping to an EPUB location from the search](https://github.com/readium/r2-navigator-kotlin/pull/111).
* The `AndroidManifest.xml` is not forcing anymore `allowBackup` and `supportsRtl`, to let reading apps manage these features themselves (contributed by [@twaddington](https://github.com/readium/r2-navigator-kotlin/pull/118)).


[unreleased]: https://github.com/readium/r2-navigator-kotlin/compare/master...HEAD
[2.0.0-alpha.1]: https://github.com/readium/r2-navigator-kotlin/compare/1.1.6...2.0.0-alpha.1
2 changes: 1 addition & 1 deletion r2-navigator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
if (findProject(':r2-shared')) {
implementation project(':r2-shared')
} else {
implementation "com.github.readium:r2-shared-kotlin:1.1.6"
implementation "com.github.readium:r2-shared-kotlin:2.0.0-alpha.1"
}

implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class R2AudiobookActivity : AppCompatActivity(), CoroutineScope, IR2Activit
title = resource.title,
locations = Locator.Locations(
fragments = listOf(
"t=${mediaPlayer?.currentPosition?.toInt() ?: 0}"
"t=${TimeUnit.MILLISECONDS.toSeconds(mediaPlayer?.currentPosition?.toLong() ?: 0)}"
),
progression = progression
)
Expand All @@ -61,11 +61,18 @@ open class R2AudiobookActivity : AppCompatActivity(), CoroutineScope, IR2Activit
}

override fun go(locator: Locator, animated: Boolean, completion: () -> Unit): Boolean {
val resourceIndex = publication.readingOrder.indexOfFirstWithHref(locator.href)
?: return false
val resourceIndex = publication.readingOrder.indexOfFirstWithHref(locator.href) ?: return false

val mediaPlayer = mediaPlayer ?: run {
pendingLocator = locator
return false
}

pendingLocator = null
currentResource = resourceIndex
mediaPlayer?.goTo(currentResource)
mediaPlayer.goTo(currentResource)
seek(locator.locations)

return true
}

Expand Down Expand Up @@ -126,6 +133,7 @@ open class R2AudiobookActivity : AppCompatActivity(), CoroutineScope, IR2Activit
private val backwardTime = 10000

var mediaPlayer: R2MediaPlayer? = null
private var pendingLocator: Locator? = null

protected var navigatorDelegate: NavigatorDelegate? = null

Expand All @@ -149,13 +157,7 @@ open class R2AudiobookActivity : AppCompatActivity(), CoroutineScope, IR2Activit

mediaPlayer = R2MediaPlayer(publication.readingOrder, this)

mediaPlayer?.goTo(currentResource)

currentLocator.value?.locations?.progression?.let { progression ->
mediaPlayer?.seekTo(progression)
seekLocation = currentLocator.value?.locations
isSeekNeeded = true
}
go(pendingLocator ?: publication.readingOrder.first().toLocator())

seekBar?.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
/**
Expand Down Expand Up @@ -289,27 +291,38 @@ open class R2AudiobookActivity : AppCompatActivity(), CoroutineScope, IR2Activit
notifyCurrentLocation()
}

private var seekLocation: Locator.Locations? = null
private var isSeekNeeded = false
var isSeekTracking = false
private fun seekIfNeeded() {
if (isSeekNeeded) {
val time = seekLocation?.fragments?.firstOrNull()?.let {
var time = it
if (time.startsWith("#t=") || time.startsWith("t=")) {
time = time.substring(time.indexOf('=') + 1)
}
time
private fun seek(locations: Locator.Locations) {
if (mediaPlayer?.isPrepared == false) {
pendingSeekLocation = locations
return
}

pendingSeekLocation = null

val time = locations.fragments.firstOrNull()?.let {
var time = it
if (time.startsWith("#t=") || time.startsWith("t=")) {
time = time.substring(time.indexOf('=') + 1)
}
time?.let {
mediaPlayer?.seekTo(TimeUnit.SECONDS.toMillis(it.toLong()).toInt())
} ?: run {
seekLocation?.progression?.let { progression ->
mediaPlayer?.seekTo(progression)
}
time
}
time?.let {
mediaPlayer?.seekTo(TimeUnit.SECONDS.toMillis(it.toLong()).toInt())
} ?: run {
val progression = locations.progression
val duration = mediaPlayer?.duration
if (progression != null && duration != null) {
mediaPlayer?.seekTo(progression * duration)
}
seekLocation = null
isSeekNeeded = false
}
}

private var pendingSeekLocation: Locator.Locations? = null
var isSeekTracking = false

private fun seekIfNeeded() {
pendingSeekLocation?.let { locations ->
seek(locations)
}
}

Expand Down Expand Up @@ -398,11 +411,9 @@ open class R2AudiobookActivity : AppCompatActivity(), CoroutineScope, IR2Activit
}
index++
}
seekLocation = locator.locations
pendingSeekLocation = locator.locations
}

isSeekNeeded = true

mediaPlayer?.goTo(currentResource)

play_pause!!.callOnClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class R2MediaPlayer(private var items: List<Link>, private var callback: MediaPl
override fun onPrepared(mp: MediaPlayer?) {
toggleProgress(false)
this.start()
callback.onPrepared()
isPrepared = true
callback.onPrepared()
}

fun startPlayer() {
Expand Down

0 comments on commit ac67a46

Please sign in to comment.