Skip to content

Commit

Permalink
chore(player): remove view interface as it is not really useful. Also…
Browse files Browse the repository at this point in the history
…, it is possible to find the same behavior with passing the player view to the controller and adding the listener.
  • Loading branch information
ThibaultBee committed Nov 9, 2023
1 parent 269f577 commit ba936c2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 73 deletions.
61 changes: 8 additions & 53 deletions player/src/main/java/video/api/player/ApiVideoPlayerController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import video.api.analytics.exoplayer.ApiVideoAnalyticsListener
import video.api.player.extensions.currentVideoOptions
import video.api.player.extensions.setMediaSource
import video.api.player.extensions.setMp4MediaSource
import video.api.player.interfaces.IExoPlayerBasedPlayerView
import video.api.player.interfaces.ISurfaceViewBasedPlayerView
import video.api.player.models.ApiVideoExoPlayerMediaFactory
import video.api.player.models.VideoOptions
import video.api.player.notifications.ApiVideoPlayerNotificationController
Expand Down Expand Up @@ -60,21 +58,21 @@ constructor(
)
) {
/**
* Creates a new controller with an [IExoPlayerBasedPlayerView].
* Creates a new controller with an [ApiVideoExoPlayerView].
*
* @param context the application context
* @param initialVideoOptions initial video options
* @param initialAutoplay initial autoplay: true to play the video immediately, false otherwise
* @param listener the [ApiVideoPlayerController.Listener] to listen to player events
* @param playerView the [IExoPlayerBasedPlayerView] interface for ExoPlayer [PlayerView] based player view
* @param playerView the player view
* @param looper the looper where call to the player are executed. By default, it is the current looper or the main looper.
*/
constructor(
context: Context,
initialVideoOptions: VideoOptions? = null,
initialAutoplay: Boolean = false,
listener: Listener? = null,
playerView: IExoPlayerBasedPlayerView,
playerView: ApiVideoExoPlayerView,
looper: Looper = Looper.myLooper() ?: Looper.getMainLooper(),
notificationController: ApiVideoPlayerNotificationController? = ApiVideoPlayerNotificationController(
context
Expand All @@ -87,41 +85,7 @@ constructor(
playerView.playerView,
looper,
notificationController
) {
addListener(playerView)
}

/**
* Creates a new controller with an [ISurfaceViewBasedPlayerView].
*
* @param context the application context
* @param initialVideoOptions initial video options
* @param initialAutoplay initial autoplay: true to play the video immediately, false otherwise
* @param listener the [ApiVideoPlayerController.Listener] to listen to player events
* @param playerView the [ISurfaceViewBasedPlayerView] interface for [SurfaceView] based player view
* @param looper the looper where call to the player are executed. By default, it is the current looper or the main looper.
*/
constructor(
context: Context,
initialVideoOptions: VideoOptions? = null,
initialAutoplay: Boolean = false,
listener: Listener? = null,
playerView: ISurfaceViewBasedPlayerView,
looper: Looper = Looper.myLooper() ?: Looper.getMainLooper(),
notificationController: ApiVideoPlayerNotificationController? = ApiVideoPlayerNotificationController(
context
)
) : this(
context,
initialVideoOptions,
initialAutoplay,
listener,
playerView.surfaceView,
looper,
notificationController
) {
addListener(playerView)
}
)

/**
* Creates a new controller with a `media3` [PlayerView].
Expand Down Expand Up @@ -598,9 +562,9 @@ constructor(
/**
* Sets the player view
*
* @param view the player view. An [ApiVideoExoPlayerView] for example.
* @param view the [ApiVideoExoPlayerView].
*/
fun setPlayerView(view: IExoPlayerBasedPlayerView) = setPlayerView(view.playerView)
fun setPlayerView(view: ApiVideoExoPlayerView) = setPlayerView(view.playerView)

/**
* Sets the player view
Expand All @@ -611,15 +575,6 @@ constructor(
playerView.player = exoplayer
}

/**
* Sets the player view
*
* @param view the [ISurfaceViewBasedPlayerView]
*/
fun setSurfaceView(view: ISurfaceViewBasedPlayerView) {
exoplayer.setVideoSurfaceView(view.surfaceView)
}

/**
* Sets the player view
*
Expand All @@ -645,8 +600,8 @@ constructor(

@SuppressLint("UnsafeOptInUsageError")
fun switchTargetView(
oldPlayerView: IExoPlayerBasedPlayerView,
newPlayerView: IExoPlayerBasedPlayerView
oldPlayerView: ApiVideoExoPlayerView,
newPlayerView: ApiVideoExoPlayerView
) = switchTargetView(oldPlayerView.playerView, newPlayerView.playerView)

companion object {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.media3.ui.AspectRatioFrameLayout.RESIZE_MODE_ZOOM
import androidx.media3.ui.PlayerView
import video.api.player.R
import video.api.player.databinding.ExoPlayerLayoutBinding
import video.api.player.interfaces.IExoPlayerBasedPlayerView
import video.api.player.models.ApiVideoPlayerFullScreenController

/**
Expand All @@ -25,11 +24,13 @@ import video.api.player.models.ApiVideoPlayerFullScreenController
*/
class ApiVideoExoPlayerView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr), IExoPlayerBasedPlayerView {
) : FrameLayout(context, attrs, defStyleAttr) {
private val binding = ExoPlayerLayoutBinding.inflate(LayoutInflater.from(context), this)

override val playerView: PlayerView
get() = binding.playerView
/**
* The ExoPlayer player view.
*/
internal val playerView = binding.playerView

/**
* Sets or gets the full screen listener.
Expand Down

0 comments on commit ba936c2

Please sign in to comment.