diff --git a/app/src/main/java/com/potyvideo/andexoplayer/MainActivityKotlin.kt b/app/src/main/java/com/potyvideo/andexoplayer/MainActivityKotlin.kt index 8ba6270..e210b3d 100644 --- a/app/src/main/java/com/potyvideo/andexoplayer/MainActivityKotlin.kt +++ b/app/src/main/java/com/potyvideo/andexoplayer/MainActivityKotlin.kt @@ -7,6 +7,7 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.AppCompatButton import com.potyvideo.library.kotlin.AndExoPlayerView +import com.potyvideo.library.kotlin.globalEnums.EnumResizeMode import com.potyvideo.library.kotlin.globalInterfaces.AndExoPlayerListener import com.potyvideo.library.kotlin.utils.PublicValues import com.potyvideo.library.utils.PathUtil @@ -25,7 +26,7 @@ class MainActivityKotlin : AppCompatActivity(), AndExoPlayerListener, View.OnCli // andExoPlayerView.setSource(videoURL) // andExoPlayerView.setShowTimeOut(0) // disable hide controller - andExoPlayerView.setResizeMode() // sync with attrs + andExoPlayerView.setResizeMode(EnumResizeMode.ZOOM) // sync with attrs andExoPlayerView.setAndExoPlayerListener(this) findViewById(R.id.local).setOnClickListener(this) @@ -34,9 +35,6 @@ class MainActivityKotlin : AppCompatActivity(), AndExoPlayerListener, View.OnCli findViewById(R.id.stream_dash).setOnClickListener(this) findViewById(R.id.stream_mkv).setOnClickListener(this) - // player controller view model - // val playerControllerViewModel = ViewModelProvider(this@MainActivityKotlin)[PlayerControllerViewModel::class.java] - // andExoPlayerView.setPlayerControllerViewModel(playerControllerViewModel) } override fun onExoPlayerError(errorMessage: String?) { @@ -48,7 +46,7 @@ class MainActivityKotlin : AppCompatActivity(), AndExoPlayerListener, View.OnCli selectLocaleVideo() } R.id.stream_mp4 -> { - loadMP4Stream(PublicValues.TEST_URL_MP4_V4) + loadMP4Stream(PublicValues.TEST_URL_MP4_V5) } R.id.stream_hls -> { loadHLSStream(PublicValues.TEST_URL_HLS) diff --git a/library/build.gradle b/library/build.gradle index 25acea5..7065f19 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -13,8 +13,8 @@ android { defaultConfig { minSdkVersion 16 targetSdkVersion 29 - versionCode 18 - versionName "2.0.2" + versionCode 19 + versionName "2.0.3" vectorDrawables.useSupportLibrary = true multiDexEnabled true diff --git a/library/src/main/java/com/potyvideo/library/kotlin/AndExoPlayerRoot.kt b/library/src/main/java/com/potyvideo/library/kotlin/AndExoPlayerRoot.kt index 1656e5d..dd5c5c7 100644 --- a/library/src/main/java/com/potyvideo/library/kotlin/AndExoPlayerRoot.kt +++ b/library/src/main/java/com/potyvideo/library/kotlin/AndExoPlayerRoot.kt @@ -59,34 +59,11 @@ abstract class AndExoPlayerRoot @JvmOverloads constructor( unMute = playerView.findViewById(R.id.exo_unmute) settingContainer = playerView.findViewById(R.id.container_setting) - // extract attrs - extractAttrs(attributeSet) - // listeners initListeners() } - private fun extractAttrs(attributeSet: AttributeSet?) { - - attributeSet.let { - val attributes: TypedArray = context.obtainStyledAttributes(it, R.styleable.AndExoPlayerView) - if (attributes.hasValue(R.styleable.AndExoPlayerView_andexo_aspect_ratio)) { - val aspectRatio = attributes.getInteger(R.styleable.AndExoPlayerView_andexo_aspect_ratio, EnumAspectRatio.ASPECT_16_9.value) - setAspectRatio(EnumAspectRatio[aspectRatio]) - } - - attributes.recycle() - } - - /* - val attributes = context.obtainStyledAttributes(attrs, R.styleable.BenefitView) - imageView.setImageDrawable(attributes.getDrawable(R.styleable.BenefitView_image)) - textView.text = attributes.getString(R.styleable.BenefitView_text) - attributes.recycle() - */ - } - private fun initListeners() { retryButton.setOnClickListener(customClickListener) backwardView.setOnClickListener(customClickListener) @@ -136,40 +113,6 @@ abstract class AndExoPlayerRoot @JvmOverloads constructor( unMute.visibility = GONE } - protected fun setAspectRatio(aspectRatio: EnumAspectRatio) { - this.currAspectRatio = aspectRatio - val value = PublicFunctions.getScreenWidth() - when (aspectRatio) { - EnumAspectRatio.ASPECT_1_1 -> playerView.layoutParams = FrameLayout.LayoutParams(value, value) - EnumAspectRatio.ASPECT_4_3 -> playerView.layoutParams = FrameLayout.LayoutParams(value, 3 * value / 4) - EnumAspectRatio.ASPECT_16_9 -> playerView.layoutParams = FrameLayout.LayoutParams(value, 9 * value / 16) - EnumAspectRatio.ASPECT_MATCH -> playerView.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) - EnumAspectRatio.ASPECT_MP3 -> { - playerView.controllerShowTimeoutMs = 0 - playerView.controllerHideOnTouch = false - val mp3Height = context.resources.getDimensionPixelSize(R.dimen.player_controller_base_height) - playerView.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mp3Height) - } - EnumAspectRatio.UNDEFINE -> { - val baseHeight = resources.getDimension(R.dimen.player_base_height).toInt() - playerView.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, baseHeight) - } - } - } - - protected fun setRepeatMode(repeatMode: EnumRepeatMode) { - this.currRepeatMode = repeatMode - } - - protected fun setResizeMode(resizeMode: EnumResizeMode) { - when (resizeMode) { - EnumResizeMode.FIT -> playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT - EnumResizeMode.FILL -> playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL - EnumResizeMode.ZOOM -> playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM - else -> playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT - } - } - protected fun setShowSetting(showSetting: Boolean = false) { if (showSetting) settingContainer.visibility = VISIBLE diff --git a/library/src/main/java/com/potyvideo/library/kotlin/AndExoPlayerView.kt b/library/src/main/java/com/potyvideo/library/kotlin/AndExoPlayerView.kt index 264aacb..36308c0 100644 --- a/library/src/main/java/com/potyvideo/library/kotlin/AndExoPlayerView.kt +++ b/library/src/main/java/com/potyvideo/library/kotlin/AndExoPlayerView.kt @@ -1,14 +1,20 @@ package com.potyvideo.library.kotlin import android.content.Context +import android.content.res.TypedArray import android.util.AttributeSet import android.view.View +import android.view.ViewGroup +import android.widget.FrameLayout import com.google.android.exoplayer2.* import com.google.android.exoplayer2.source.TrackGroupArray import com.google.android.exoplayer2.trackselection.TrackSelectionArray import com.google.android.exoplayer2.ui.AspectRatioFrameLayout import com.google.android.exoplayer2.util.MimeTypes +import com.potyvideo.library.R +import com.potyvideo.library.kotlin.globalEnums.EnumAspectRatio import com.potyvideo.library.kotlin.globalEnums.EnumRepeatMode +import com.potyvideo.library.kotlin.globalEnums.EnumResizeMode import com.potyvideo.library.kotlin.globalInterfaces.AndExoPlayerListener import com.potyvideo.library.kotlin.utils.DoubleClick import com.potyvideo.library.kotlin.utils.DoubleClickListener @@ -60,6 +66,28 @@ class AndExoPlayerView( init { player.addListener(this) + + extractAttrs(attributeSet) + } + + private fun extractAttrs(attributeSet: AttributeSet?) { + + attributeSet.let { + val attributes: TypedArray = context.obtainStyledAttributes(it, R.styleable.AndExoPlayerView) + if (attributes.hasValue(R.styleable.AndExoPlayerView_andexo_aspect_ratio)) { + val aspectRatio = attributes.getInteger(R.styleable.AndExoPlayerView_andexo_aspect_ratio, EnumAspectRatio.ASPECT_16_9.value) + setAspectRatio(EnumAspectRatio[aspectRatio]) + } + + attributes.recycle() + } + + /* + val attributes = context.obtainStyledAttributes(attrs, R.styleable.BenefitView) + imageView.setImageDrawable(attributes.getDrawable(R.styleable.BenefitView_image)) + textView.text = attributes.getString(R.styleable.BenefitView_text) + attributes.recycle() + */ } override fun onPlaybackParametersChanged(playbackParameters: PlaybackParameters) { @@ -186,10 +214,6 @@ class AndExoPlayerView( playerView.controllerHideOnTouch = false } - fun setResizeMode() { - playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL - } - fun seekBackward(backwardValue: Int = 10000) { var seekValue = player.currentPosition - backwardValue if (seekValue < 0) seekValue = 0 @@ -217,7 +241,7 @@ class AndExoPlayerView( showUnMuteButton() } - fun setLoopMode(repeatModeMode: EnumRepeatMode = EnumRepeatMode.REPEAT_OFF) { + fun setRepeatMode(repeatModeMode: EnumRepeatMode = EnumRepeatMode.REPEAT_OFF) { when (repeatModeMode) { EnumRepeatMode.REPEAT_OFF -> { player.repeatMode = Player.REPEAT_MODE_OFF @@ -231,4 +255,34 @@ class AndExoPlayerView( } } + fun setAspectRatio(aspectRatio: EnumAspectRatio) { + this.currAspectRatio = aspectRatio + val value = com.potyvideo.library.utils.PublicFunctions.getScreenWidth() + when (aspectRatio) { + EnumAspectRatio.ASPECT_1_1 -> playerView.layoutParams = FrameLayout.LayoutParams(value, value) + EnumAspectRatio.ASPECT_4_3 -> playerView.layoutParams = FrameLayout.LayoutParams(value, 3 * value / 4) + EnumAspectRatio.ASPECT_16_9 -> playerView.layoutParams = FrameLayout.LayoutParams(value, 9 * value / 16) + EnumAspectRatio.ASPECT_MATCH -> playerView.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) + EnumAspectRatio.ASPECT_MP3 -> { + playerView.controllerShowTimeoutMs = 0 + playerView.controllerHideOnTouch = false + val mp3Height = context.resources.getDimensionPixelSize(R.dimen.player_controller_base_height) + playerView.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mp3Height) + } + EnumAspectRatio.UNDEFINE -> { + val baseHeight = resources.getDimension(R.dimen.player_base_height).toInt() + playerView.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, baseHeight) + } + } + } + + fun setResizeMode(resizeMode: EnumResizeMode) { + when (resizeMode) { + EnumResizeMode.FIT -> playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT + EnumResizeMode.FILL -> playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL + EnumResizeMode.ZOOM -> playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM + else -> playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT + } + } + } \ No newline at end of file diff --git a/library/src/main/java/com/potyvideo/library/kotlin/utils/PublicValues.kt b/library/src/main/java/com/potyvideo/library/kotlin/utils/PublicValues.kt index 80ad612..abc8a7b 100644 --- a/library/src/main/java/com/potyvideo/library/kotlin/utils/PublicValues.kt +++ b/library/src/main/java/com/potyvideo/library/kotlin/utils/PublicValues.kt @@ -37,6 +37,7 @@ class PublicValues { const val TEST_URL_MP4_V2 = "https://hajifirouz2.cdn.asset.aparat.com/aparat-video/069670345914165d063b0738fc9f81b532132940-480p.mp4?wmsAuthSign=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbiI6ImMxMjg4ZDQzM2NhNzZhZmRjNGM1M2E3NTQyMjIwNTQwIiwiZXhwIjoxNjE4MzQ1NzA4LCJpc3MiOiJTYWJhIElkZWEgR1NJRyJ9.TbxCUzv7ke-TuYsxekYjN3VVnpG48uWOQ-7iN_ZH3_g" const val TEST_URL_MP4_V3 = "https://www.rmp-streaming.com/media/big-buck-bunny-360p.mp4" const val TEST_URL_MP4_V4 = "https://backyard.vaslapp.com/res/036e77f0-a94e-4165-9832-1a8e39c1e089/USER_FILES/6084024b90c61d0001471b0c/1619507956737/file.mp4" + const val TEST_URL_MP4_V5 = "https://backyard.vaslapp.com/res/036e77f0-a94e-4165-9832-1a8e39c1e089/USER_FILES/6084024b90c61d0001471b0c/1619507956737/file.mp4" const val TEST_URL_HLS = "https://content.jwplatform.com/manifests/yp34SRmf.m3u8"