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

Commit

Permalink
Add an Audiobook navigator based on MediaSession (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu authored Sep 22, 2021
1 parent 3010a60 commit 1f353fe
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package org.readium.r2.shared

@RequiresOptIn(message = "Support for PDF is still experimental. The API may be changed in the future without notice.")
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS, AnnotationTarget.PROPERTY)
annotation class PdfSupport

@RequiresOptIn(message = "Support for SearchService is still experimental. The API may be changed in the future without notice.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ interface Resource : SuspendingCloseable {
class Unavailable(cause: Throwable? = null)
: Exception(R.string.r2_shared_resource_exception_unavailable, cause)

/**
* The Internet connection appears to be offline.
*/
object Offline : Exception(R.string.r2_shared_resource_exception_offline)

/**
* Equivalent to a 507 HTTP error.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import java.io.InputStream
/**
* Input stream reading a [Resource]'s content.
*
* The underlying resource will be automatically closed at the same time that this stream is.
* */
* If you experience bad performances, consider wrapping the stream in a BufferedInputStream. This
* is particularly useful when streaming deflated ZIP entries.
*/
class ResourceInputStream(
private val resource: Resource,
val range: LongRange? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
package org.readium.r2.shared.publication

import android.os.Parcelable
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.parcelize.Parcelize
import org.json.JSONArray
import org.json.JSONObject
Expand All @@ -22,6 +24,7 @@ import org.readium.r2.shared.toJSON
import org.readium.r2.shared.util.Href
import org.readium.r2.shared.util.logging.WarningLogger
import org.readium.r2.shared.util.logging.log
import java.io.File

/**
* Holds the metadata of a Readium publication, as described in the Readium Web Publication Manifest.
Expand Down Expand Up @@ -75,7 +78,7 @@ data class Manifest(
companion object {

/**
* Parses a [Publication] from its RWPM JSON representation.
* Parses a [Manifest] from its RWPM JSON representation.
*
* If the publication can't be parsed, a warning will be logged with [warnings].
* https://readium.org/webpub-manifest/
Expand Down Expand Up @@ -106,7 +109,7 @@ data class Manifest(

val metadata = Metadata.fromJSON(json.remove("metadata") as? JSONObject, normalizeHref, warnings)
if (metadata == null) {
warnings?.log(Publication::class.java, "[metadata] is required", json)
warnings?.log(Manifest::class.java, "[metadata] is required", json)
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ import kotlin.reflect.KClass

internal typealias ServiceFactory = (Publication.Service.Context) -> Publication.Service?

/**
* A reference uniquely identifying a publication in the reading app.
*
* For example, a database primary key for a local publication, or a source URL for a remote one.
*
* We can't use publication.metadata.identifier directly because it might be null or not really
* unique in the reading app. That's why sometimes we require an ID provided by the app.
*/
typealias PublicationId = String

/**
* The Publication shared model is the entry-point for all the metadata and services
* related to a Readium publication.
Expand Down
1 change: 1 addition & 0 deletions r2-shared/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<string name="r2.shared.resource.exception.not_found">Resource not found</string>
<string name="r2.shared.resource.exception.forbidden">You are not allowed to access the resource</string>
<string name="r2.shared.resource.exception.unavailable">The resource is currently unavailable, please try again later</string>
<string name="r2_shared_resource_exception_offline">The Internet connection appears to be offline</string>
<string name="r2.shared.resource.exception.out_of_memory">The resource is too large to be read on this device</string>
<string name="r2.shared.resource.exception.cancelled">The request was cancelled</string>
<string name="r2.shared.resource.exception.other">A service error occurred</string>
Expand Down

0 comments on commit 1f353fe

Please sign in to comment.