Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation and Warning cleanup #791

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
import android.view.accessibility.CaptioningManager
import androidx.annotation.OptIn
import androidx.media3.common.text.Cue
import com.devbrackets.android.exomedia.core.listener.CaptionListener
import androidx.media3.common.text.CueGroup
import androidx.media3.common.util.UnstableApi
import androidx.media3.ui.CaptionStyleCompat
import com.devbrackets.android.exomedia.core.listener.CaptionListener

@Suppress("MemberVisibilityCanBePrivate", "unused")
/**
* A view for displaying subtitle [Cue]s.
*/
@OptIn(UnstableApi::class)
@Suppress("MemberVisibilityCanBePrivate", "unused")
class SubtitleView
@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : View(context, attrs), CaptionListener {

private val painters = mutableListOf<SubtitlePainter>()

private var cues: List<Cue>? = null
private var cueGroup: CueGroup? = null
@Cue.TextSizeType
private var textSizeType = Cue.TEXT_SIZE_TYPE_FRACTIONAL
private var textSize = DEFAULT_TEXT_SIZE_FRACTION
Expand All @@ -56,22 +60,22 @@ class SubtitleView
return CaptionStyleCompat.createFromCaptionStyle(captioningManager.userStyle)
}

override fun onCues(cues: List<Cue>) {
setCues(cues)
override fun onCues(cueGroup: CueGroup) {
setCues(cueGroup)
}

/**
* Sets the cues to be displayed by the view.
*
* @param cues The cues to display, or null to clear the cues.
*/
fun setCues(cues: List<Cue>?) {
if (this.cues === cues) {
fun setCues(cueGroup: CueGroup?) {
if (this.cueGroup === cueGroup) {
return
}
this.cues = cues
this.cueGroup = cueGroup
// Ensure we have sufficient painters.
val cueCount = cues?.size ?: 0
val cueCount = cueGroup?.cues?.size ?: 0
while (painters.size < cueCount) {
painters.add(SubtitlePainter(context))
}
Expand Down Expand Up @@ -219,7 +223,7 @@ class SubtitleView
}

public override fun dispatchDraw(canvas: Canvas) {
val cueCount = if (cues == null) 0 else cues!!.size
val cueCount = cueGroup?.cues?.size ?: 0
val rawTop = top
val rawBottom = bottom

Expand All @@ -242,7 +246,7 @@ class SubtitleView
}

for (i in 0 until cueCount) {
val cue = cues?.get(i) ?: break
val cue = cueGroup?.cues?.get(i) ?: break
val cueTextSizePx = resolveCueTextSize(cue, rawViewHeight, viewHeightMinusPadding)
val painter = painters[i]
painter.draw(
Expand Down Expand Up @@ -303,13 +307,4 @@ class SubtitleView
const val DEFAULT_BOTTOM_PADDING_FRACTION = 0.08f
}

}
/**
* Sets the text size to be a fraction of the view's remaining height after its top and bottom
* padding have been subtracted.
*
*
* Equivalent to `#setFractionalTextSize(fractionOfHeight, false)`.
*
* @param fractionOfHeight A fraction between 0 and 1.
*/
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.devbrackets.android.exomedia.core

import androidx.annotation.OptIn
import androidx.media3.common.*
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.DecoderCounters
import androidx.media3.exoplayer.analytics.AnalyticsListener
import androidx.media3.exoplayer.source.LoadEventInfo
Expand All @@ -11,45 +13,67 @@ import java.io.IOException
* A simple analytics delegate that handles a nullable listener delegate which allows us to use
* class delegation in the [ListenerMux]
*/
@OptIn(UnstableApi::class)
class AnalyticsDelegate(
var listener: AnalyticsListener? = null
): AnalyticsListener {
override fun onMetadata(eventTime: AnalyticsListener.EventTime, metadata: Metadata) {
listener?.onMetadata(eventTime, metadata)
}

@Deprecated("Deprecated in Java")
@Deprecated(
"Replace with onVideoSizeChanged(EventTime, VideoSize)",
replaceWith = ReplaceWith(
expression = "onVideoSizeChanged(eventTime, VideoSize(width, height, unappliedRotationDegrees, pixelWidthHeightRatio))",
imports = [
"androidx.media3.common.VideoSize"
]
)
)
override fun onVideoSizeChanged(
eventTime: AnalyticsListener.EventTime,
width: Int,
height: Int,
unappliedRotationDegrees: Int,
pixelWidthHeightRatio: Float
) {
@Suppress("DEPRECATION")
listener?.onVideoSizeChanged(eventTime, width, height, unappliedRotationDegrees, pixelWidthHeightRatio)
}

@Deprecated("Deprecated in Java")
override fun onVideoSizeChanged(eventTime: AnalyticsListener.EventTime, videoSize: VideoSize) {
listener?.onVideoSizeChanged(eventTime, videoSize)
}

@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onPlaybackStateChanged(EventTime, Int) or onPlayWhenReadyChanged(EventTime, Boolean, Int)")
override fun onPlayerStateChanged(eventTime: AnalyticsListener.EventTime, playWhenReady: Boolean, playbackState: Int) {
@Suppress("DEPRECATION")
listener?.onPlayerStateChanged(eventTime, playWhenReady, playbackState)
}

override fun onTimelineChanged(eventTime: AnalyticsListener.EventTime, reason: Int) {
listener?.onTimelineChanged(eventTime, reason)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onPositionDiscontinuity(EventTime, PositionInfo, PositionInfo, Int)")
override fun onPositionDiscontinuity(eventTime: AnalyticsListener.EventTime, reason: Int) {
@Suppress("DEPRECATION")
listener?.onPositionDiscontinuity(eventTime, reason)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onPositionDiscontinuity(EventTime, PositionInfo, PositionInfo, Int)")
override fun onSeekStarted(eventTime: AnalyticsListener.EventTime) {
@Suppress("DEPRECATION")
listener?.onSeekStarted(eventTime)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onPositionDiscontinuity(EventTime, PositionInfo, PositionInfo, Int)")
override fun onSeekProcessed(eventTime: AnalyticsListener.EventTime) {
@Suppress("DEPRECATION")
listener?.onSeekProcessed(eventTime)
}

Expand All @@ -65,8 +89,14 @@ class AnalyticsDelegate(
listener?.onShuffleModeChanged(eventTime, shuffleModeEnabled)
}

@Deprecated("Deprecated in Java")
@Deprecated(
"Replace with onIsLoadingChanged(EventTime, Boolean)",
ReplaceWith(
expression = "onIsLoadingChanged(eventTime, isLoading)"
)
)
override fun onLoadingChanged(eventTime: AnalyticsListener.EventTime, isLoading: Boolean) {
@Suppress("DEPRECATION")
listener?.onLoadingChanged(eventTime, isLoading)
}

Expand Down Expand Up @@ -120,8 +150,10 @@ class AnalyticsDelegate(
listener?.onVolumeChanged(eventTime, volume)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onDrmSessionAcquired(EventTime, Int)")
override fun onDrmSessionAcquired(eventTime: AnalyticsListener.EventTime) {
@Suppress("DEPRECATION")
listener?.onDrmSessionAcquired(eventTime)
}

Expand All @@ -133,23 +165,31 @@ class AnalyticsDelegate(
listener?.onAudioAttributesChanged(eventTime, audioAttributes)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onAudioEnabled(EventTime, DecoderCounters) and onVideoEnabled(EventTime, DecoderCounters)")
override fun onDecoderEnabled(eventTime: AnalyticsListener.EventTime, trackType: Int, decoderCounters: DecoderCounters) {
@Suppress("DEPRECATION")
listener?.onDecoderEnabled(eventTime, trackType, decoderCounters)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onAudioDecoderInitialized(EventTime, String, Long, Long) and onVideoDecoderInitialized(EventTime, String, Long, Long)")
override fun onDecoderInitialized(eventTime: AnalyticsListener.EventTime, trackType: Int, decoderName: String, initializationDurationMs: Long) {
@Suppress("DEPRECATION")
listener?.onDecoderInitialized(eventTime, trackType, decoderName, initializationDurationMs)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onAudioInputFormatChanged(EventTime, Format, DecoderReuseEvaluation) and onVideoInputFormatChanged(EventTime, Format, DecoderReuseEvaluation)")
override fun onDecoderInputFormatChanged(eventTime: AnalyticsListener.EventTime, trackType: Int, format: Format) {
@Suppress("DEPRECATION")
listener?.onDecoderInputFormatChanged(eventTime, trackType, format)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onAudioDisabled(EventTime, DecoderCounters) and onVideoDisabled(EventTime, DecoderCounters)")
override fun onDecoderDisabled(eventTime: AnalyticsListener.EventTime, trackType: Int, decoderCounters: DecoderCounters) {
@Suppress("DEPRECATION")
listener?.onDecoderDisabled(eventTime, trackType, decoderCounters)
}

Expand Down Expand Up @@ -213,13 +253,17 @@ class AnalyticsDelegate(
listener?.onAudioEnabled(eventTime, counters)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onAudioDecoderInitialized(EventTime, String, Long, Long)")
override fun onAudioDecoderInitialized(eventTime: AnalyticsListener.EventTime, decoderName: String, initializationDurationMs: Long) {
@Suppress("DEPRECATION")
listener?.onAudioDecoderInitialized(eventTime, decoderName, initializationDurationMs)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onAudioInputFormatChanged(EventTime, Format, DecoderReuseEvaluation)")
override fun onAudioInputFormatChanged(eventTime: AnalyticsListener.EventTime, format: Format) {
@Suppress("DEPRECATION")
listener?.onAudioInputFormatChanged(eventTime, format)
}

Expand All @@ -239,13 +283,17 @@ class AnalyticsDelegate(
listener?.onVideoEnabled(eventTime, counters)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onVideoDecoderInitialized(EventTime, String, Long, Long)")
override fun onVideoDecoderInitialized(eventTime: AnalyticsListener.EventTime, decoderName: String, initializationDurationMs: Long) {
@Suppress("DEPRECATION")
listener?.onVideoDecoderInitialized(eventTime, decoderName, initializationDurationMs)
}

@Deprecated("Deprecated in Java")
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Replace with onVideoInputFormatChanged(EventTime, Format, DecoderReuseEvaluation)")
override fun onVideoInputFormatChanged(eventTime: AnalyticsListener.EventTime, format: Format) {
@Suppress("DEPRECATION")
listener?.onVideoInputFormatChanged(eventTime, format)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.devbrackets.android.exomedia.core.listener


import androidx.media3.common.text.Cue
import androidx.media3.common.text.CueGroup

/**
* A listener for receiving notifications of timed text.
*/
interface CaptionListener {
fun onCues(cues: List<Cue>)
fun onCues(cueGroup: CueGroup)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.devbrackets.android.exomedia.core.renderer

import android.content.Context
import android.os.Handler
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import com.devbrackets.android.exomedia.core.renderer.provider.AudioRenderProvider
import com.devbrackets.android.exomedia.core.renderer.provider.CaptionRenderProvider
import com.devbrackets.android.exomedia.core.renderer.provider.MetadataRenderProvider
Expand All @@ -13,6 +15,7 @@ import androidx.media3.exoplayer.metadata.MetadataOutput
import androidx.media3.exoplayer.text.TextOutput
import androidx.media3.exoplayer.video.VideoRendererEventListener

@OptIn(UnstableApi::class)
class PlayerRendererFactory(
private val context: Context
): RenderersFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package com.devbrackets.android.exomedia.core.renderer.provider

import android.content.Context
import android.os.Handler
import com.devbrackets.android.exomedia.core.renderer.RendererType
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.Renderer
import androidx.media3.exoplayer.audio.AudioCapabilities
import androidx.media3.exoplayer.audio.AudioRendererEventListener
import androidx.media3.exoplayer.audio.MediaCodecAudioRenderer
import androidx.media3.exoplayer.mediacodec.MediaCodecSelector
import com.devbrackets.android.exomedia.core.renderer.RendererType

@OptIn(UnstableApi::class)
open class AudioRenderProvider : RenderProvider {
private var latestRenderers: List<Renderer> = emptyList()

Expand All @@ -35,9 +38,7 @@ open class AudioRenderProvider : RenderProvider {
// Adds any registered classes
rendererClasses().forEach { className ->
try {
val clazz = Class.forName(className)
val constructor = clazz.getConstructor(Handler::class.java, AudioRendererEventListener::class.java)
val renderer = constructor.newInstance(handler, listener) as Renderer
val renderer = buildRenderer(className, handler, listener)
renderers.add(renderer)
} catch (e: Exception) {
// Purposefully left blank
Expand All @@ -48,4 +49,19 @@ open class AudioRenderProvider : RenderProvider {
latestRenderers = it
}
}

private fun buildRenderer(
className: String,
handler: Handler,
listener: AudioRendererEventListener
): Renderer {
val rendererClass = Class.forName(className)

val constructor = rendererClass.getConstructor(
Long::class.javaPrimitiveType,
AudioRendererEventListener::class.java
)

return constructor.newInstance(handler, listener) as Renderer
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.devbrackets.android.exomedia.core.renderer.provider

import android.os.Handler
import com.devbrackets.android.exomedia.core.renderer.RendererType
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.Renderer
import androidx.media3.exoplayer.text.TextOutput
import androidx.media3.exoplayer.text.TextRenderer
import com.devbrackets.android.exomedia.core.renderer.RendererType

@OptIn(UnstableApi::class)
class CaptionRenderProvider: RenderProvider {
private var latestRenderers: List<Renderer> = emptyList()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.devbrackets.android.exomedia.core.renderer.provider

import android.os.Handler
import com.devbrackets.android.exomedia.core.renderer.RendererType
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.Renderer
import androidx.media3.exoplayer.metadata.MetadataDecoderFactory
import androidx.media3.exoplayer.metadata.MetadataOutput
import androidx.media3.exoplayer.metadata.MetadataRenderer
import com.devbrackets.android.exomedia.core.renderer.RendererType

@OptIn(UnstableApi::class)
class MetadataRenderProvider: RenderProvider {
private var latestRenderers: List<Renderer> = emptyList()

Expand Down
Loading