Skip to content

Commit

Permalink
Deprecate media1 and media2 navigators (readium#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed May 7, 2024
1 parent 0f23b6b commit 091f9ac
Show file tree
Hide file tree
Showing 31 changed files with 41 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.readium.r2.shared.publication.Publication
import org.readium.r2.shared.publication.services.cover

@Suppress("DEPRECATION")
@ExperimentalMedia2
internal class DefaultMetadataFactory(private val publication: Publication) : MediaMetadataFactory {

private val coroutineScope =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import com.google.android.exoplayer2.upstream.DataSpec
import com.google.android.exoplayer2.upstream.TransferListener
import java.io.IOException
import kotlinx.coroutines.runBlocking
import org.readium.r2.shared.InternalReadiumApi
import org.readium.r2.shared.publication.Publication
import org.readium.r2.shared.util.data.ReadException
import org.readium.r2.shared.util.getOrThrow
import org.readium.r2.shared.util.resource.Resource
import org.readium.r2.shared.util.resource.buffered
import org.readium.r2.shared.util.toUrl

@InternalReadiumApi
public sealed class ExoPlayerDataSourceException(message: String, cause: Throwable?) : IOException(
message,
cause
Expand All @@ -40,6 +42,7 @@ public sealed class ExoPlayerDataSourceException(message: String, cause: Throwab
/**
* An ExoPlayer's [DataSource] which retrieves resources from a [Publication].
*/
@InternalReadiumApi
public class ExoPlayerDataSource internal constructor(private val publication: Publication) : BaseDataSource(/* isNetwork = */
true
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
package org.readium.navigator.media2

import androidx.media2.common.MediaMetadata
import org.readium.r2.shared.InternalReadiumApi

/**
* Factory for the [MediaMetadata] associated with the publication and its resources.
*
* The metadata are used for example in the media-style Android notification.
*/
@Deprecated("Use the new MediaMetadataFactory from the readium-navigator-media-common module.")
@InternalReadiumApi
public interface MediaMetadataFactory {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.readium.navigator.media2.MediaNavigator.Companion.create
import org.readium.r2.navigator.Navigator
import org.readium.r2.navigator.extensions.normalizeLocator
import org.readium.r2.shared.DelicateReadiumApi
import org.readium.r2.shared.InternalReadiumApi
import org.readium.r2.shared.publication.Link
import org.readium.r2.shared.publication.Locator
import org.readium.r2.shared.publication.Publication
Expand All @@ -55,8 +56,10 @@ import timber.log.Timber
* providing [create] with it. If you don't, ExoPlayer will be used, without cache.
* You can build your own [SessionPlayer] based on [ExoPlayer] using [ExoPlayerDataSource].
*/
@ExperimentalMedia2
@Deprecated("Use the new AudioNavigator from the readium-navigator-media-audio module.")
@Deprecated(
"Use the new AudioNavigator from the readium-navigator-media-audio module. This class will be removed in a future 3.x release."
)
@InternalReadiumApi
@OptIn(ExperimentalTime::class)
public class MediaNavigator private constructor(
public val publication: Publication,
Expand Down Expand Up @@ -393,7 +396,6 @@ public class MediaNavigator private constructor(
return true
}

@ExperimentalMedia2
public companion object {

public suspend fun create(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import androidx.media2.common.MediaItem
import androidx.media2.common.MediaMetadata
import androidx.media2.common.SessionPlayer
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import timber.log.Timber

@OptIn(ExperimentalTime::class)
internal class SessionPlayerCallback(
private val positionRefreshDelay: Duration,
private val seekCompletedSender: SendChannel<Long>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.channels.ReceiveChannel
Expand All @@ -42,7 +41,6 @@ import timber.log.Timber
* - in case of failure, the playback can be left in an intermediate state
* - the behaviour is undefined if any external controller takes actions at the same time
*/
@OptIn(ExperimentalTime::class)
internal class SessionPlayerFacade(
private val sessionPlayer: SessionPlayer,
private val seekCompletedReceiver: ReceiveChannel<Long>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,39 +137,32 @@ internal val SessionPlayer.playbackSpeedNullable
internal val SessionPlayer.currentIndexNullable
get() = currentMediaItemIndex.takeUnless { it == SessionPlayer.INVALID_ITEM_INDEX }

@ExperimentalTime
internal val SessionPlayer.currentPositionDuration: Duration?
get() = msToDuration(currentPosition)

@ExperimentalTime
internal val SessionPlayer.bufferedPositionDuration: Duration?
get() = msToDuration(bufferedPosition)

@ExperimentalTime
internal val SessionPlayer.currentDuration: Duration?
get() = msToDuration(duration)

@ExperimentalTime
private fun msToDuration(ms: Long): Duration? =
if (ms == SessionPlayer.UNKNOWN_TIME) {
null
} else {
ms.milliseconds
}

@ExperimentalTime
internal val MediaMetadata.duration: Duration?
get() = getLong(MediaMetadata.METADATA_KEY_DURATION)
.takeUnless { it == 0L }
?.milliseconds

@ExperimentalTime
internal val List<MediaMetadata>.durations: List<Duration>?
get() {
val durations = mapNotNull { it.duration }
return durations.takeIf { it.size == this.size }
}

@ExperimentalTime
internal val List<MediaItem>.metadata: List<MediaMetadata>
get() = map { it.metadata!! }
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
package org.readium.navigator.media2

import kotlin.time.Duration
import kotlin.time.ExperimentalTime

/**
* Computes relative seeks across playlist items.
*/
@ExperimentalTime
internal object SmartSeeker {

data class Result(val index: Int, val position: Duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import org.readium.r2.shared.util.Url
/**
* A navigator able to render arbitrary decorations over a publication.
*/
@ExperimentalDecorator
public interface DecorableNavigator : Navigator {
/**
* Declares the current state of the decorations in the given decoration [group].
Expand Down Expand Up @@ -98,7 +97,6 @@ public interface DecorableNavigator : Navigator {
* @param extras Additional context data specific to a reading app. Readium does not use it.
*/
@Parcelize
@ExperimentalDecorator
public data class Decoration(
val id: DecorationId,
val locator: Locator,
Expand Down Expand Up @@ -145,11 +143,9 @@ public data class Decoration(
}

/** Unique identifier for a decoration. */
@ExperimentalDecorator
public typealias DecorationId = String

/** Represents an atomic change in a list of [Decoration] objects. */
@ExperimentalDecorator
public sealed class DecorationChange {
public data class Added(val decoration: Decoration) : DecorationChange()
public data class Updated(val decoration: Decoration) : DecorationChange()
Expand All @@ -162,7 +158,6 @@ public sealed class DecorationChange {
*
* The changes need to be applied in the same order, one by one.
*/
@ExperimentalDecorator
public suspend fun List<Decoration>.changesByHref(target: List<Decoration>): Map<Url, List<DecorationChange>> = withContext(
Dispatchers.Default
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public interface IR2TTS
* A navigator rendering an audio or video publication.
*/
@Deprecated("Use the new readium-navigator-media modules.")
@OptIn(ExperimentalAudiobook::class)
public interface MediaNavigator : Navigator {

/**
Expand Down
46 changes: 0 additions & 46 deletions readium/navigator/src/main/java/org/readium/r2/navigator/OptIn.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import org.readium.r2.shared.util.toUrl
import org.readium.r2.shared.util.use
import timber.log.Timber

@OptIn(ExperimentalDecorator::class, ExperimentalReadiumApi::class)
@OptIn(ExperimentalReadiumApi::class)
internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebView(context, attrs) {

interface Listener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package org.readium.r2.navigator.epub

import androidx.fragment.app.FragmentFactory
import org.readium.r2.navigator.ExperimentalDecorator
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.publication.Link
import org.readium.r2.shared.publication.Locator
Expand Down Expand Up @@ -52,7 +51,6 @@ public class EpubNavigatorFactory(
* pagination.
* @param configuration Additional configuration.
*/
@OptIn(ExperimentalDecorator::class)
public fun createFragmentFactory(
initialLocator: Locator?,
readingOrder: List<Link>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import org.json.JSONObject
import org.readium.r2.navigator.DecorableNavigator
import org.readium.r2.navigator.Decoration
import org.readium.r2.navigator.DecorationId
import org.readium.r2.navigator.ExperimentalDecorator
import org.readium.r2.navigator.HyperlinkNavigator
import org.readium.r2.navigator.NavigatorFragment
import org.readium.r2.navigator.OverflowableNavigator
Expand Down Expand Up @@ -108,7 +107,7 @@ public typealias JavascriptInterfaceFactory = (resource: Link) -> Any?
*
* To use this [Fragment], create a factory with `EpubNavigatorFragment.createFactory()`.
*/
@OptIn(ExperimentalDecorator::class, ExperimentalReadiumApi::class, DelicateReadiumApi::class)
@OptIn(ExperimentalReadiumApi::class, DelicateReadiumApi::class)
public class EpubNavigatorFragment internal constructor(
publication: Publication,
private val initialLocator: Locator?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal enum class DualPage {
AUTO, OFF, ON
}

@OptIn(ExperimentalReadiumApi::class, ExperimentalDecorator::class, DelicateReadiumApi::class)
@OptIn(ExperimentalReadiumApi::class, DelicateReadiumApi::class)
internal class EpubNavigatorViewModel(
application: Application,
val publication: Publication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package org.readium.r2.navigator.epub.extensions
import org.json.JSONObject
import org.readium.r2.navigator.Decoration
import org.readium.r2.navigator.DecorationChange
import org.readium.r2.navigator.ExperimentalDecorator
import org.readium.r2.navigator.html.HtmlDecorationTemplates
import timber.log.Timber

Expand All @@ -18,7 +17,6 @@ import timber.log.Timber
/**
* Generates the JavaScript used to apply the receiver list of [DecorationChange] in a web view.
*/
@ExperimentalDecorator
internal fun List<DecorationChange>.javascriptForGroup(
group: String,
templates: HtmlDecorationTemplates
Expand All @@ -38,7 +36,6 @@ internal fun List<DecorationChange>.javascriptForGroup(
/**
* Generates the JavaScript used to apply the receiver [DecorationChange] in a web view.
*/
@ExperimentalDecorator
internal fun DecorationChange.javascript(templates: HtmlDecorationTemplates): String? {
fun toJSON(decoration: Decoration): JSONObject? {
val template = templates[decoration.style::class] ?: run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import kotlinx.parcelize.Parcelize
import org.json.JSONObject
import org.readium.r2.navigator.Decoration
import org.readium.r2.navigator.Decoration.Style
import org.readium.r2.navigator.ExperimentalDecorator
import org.readium.r2.shared.JSONable

/**
Expand All @@ -36,7 +35,6 @@ import org.readium.r2.shared.JSONable
* and IDs to avoid conflicts with the HTML resource itself. Best practice is to prefix with
* your app name. r2- and readium- are reserved by the Readium toolkit.
*/
@ExperimentalDecorator
public data class HtmlDecorationTemplate(
val layout: Layout,
val width: Width = Width.WRAP,
Expand Down Expand Up @@ -168,7 +166,6 @@ public data class HtmlDecorationTemplate(
}
}

@ExperimentalDecorator
public class HtmlDecorationTemplates private constructor(
internal val styles: MutableMap<KClass<*>, HtmlDecorationTemplate> = mutableMapOf()
) : JSONable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import kotlinx.coroutines.MainScope
import kotlinx.coroutines.async
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import org.readium.r2.navigator.ExperimentalAudiobook
import org.readium.r2.navigator.R
import org.readium.r2.navigator.extensions.timeWithDuration
import org.readium.r2.shared.InternalReadiumApi
import org.readium.r2.shared.extensions.findInstance
import org.readium.r2.shared.publication.Link
import org.readium.r2.shared.publication.Locator
Expand All @@ -59,7 +59,7 @@ import timber.log.Timber
/**
* An implementation of [MediaPlayer] using ExoPlayer.
*/
@ExperimentalAudiobook
@InternalReadiumApi
public class ExoMediaPlayer(
context: Context,
mediaSession: MediaSessionCompat,
Expand Down
Loading

0 comments on commit 091f9ac

Please sign in to comment.