Skip to content

Commit

Permalink
added custom header support into MagicalExoPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza Amuzadeh committed May 30, 2021
1 parent caa7336 commit 73e0a6b
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
applicationId "com.potyvideo.andexoplayer"
minSdkVersion 16
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MainActivityKotlin : AppCompatActivity(), AndExoPlayerListener, View.OnCli

andExoPlayerView = findViewById(R.id.andExoPlayerView)

andExoPlayerView.setResizeMode(EnumResizeMode.FIT) // sync with attrs
andExoPlayerView.setResizeMode(EnumResizeMode.ZOOM) // sync with attrs
andExoPlayerView.setAndExoPlayerListener(this)

findViewById<AppCompatButton>(R.id.local).setOnClickListener(this)
Expand All @@ -33,6 +33,9 @@ class MainActivityKotlin : AppCompatActivity(), AndExoPlayerListener, View.OnCli
findViewById<AppCompatButton>(R.id.stream_dash).setOnClickListener(this)
findViewById<AppCompatButton>(R.id.stream_mkv).setOnClickListener(this)

// starter stream
loadMP4Stream(PublicValues.TEST_URL_MP4_V3)

}

override fun onExoPlayerError(errorMessage: String?) {
Expand All @@ -44,7 +47,7 @@ class MainActivityKotlin : AppCompatActivity(), AndExoPlayerListener, View.OnCli
selectLocaleVideo()
}
R.id.stream_mp4 -> {
loadMP4Stream(PublicValues.TEST_URL_MP4)
loadMP4Stream(PublicValues.TEST_URL_MP4_V3)
}
R.id.stream_hls -> {
loadHLSStream(PublicValues.TEST_URL_HLS)
Expand Down Expand Up @@ -85,7 +88,10 @@ class MainActivityKotlin : AppCompatActivity(), AndExoPlayerListener, View.OnCli
intent.type = "video/*"
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true)
intent.action = Intent.ACTION_GET_CONTENT
startActivityForResult(Intent.createChooser(intent, "Select Video"), PublicValues.request_code_select_video)
startActivityForResult(
Intent.createChooser(intent, "Select Video"),
PublicValues.request_code_select_video
)
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:andexo_aspect_ratio="aspect_16_9"
app:andexo_full_screen="true"
app:andexo_loop="finite"
app:andexo_play_when_ready="true"
app:andexo_resize_mode="Fit"
app:andexo_show_controller="true" />
app:andexo_show_controller="true"
app:andexo_show_full_screen="true" />

<LinearLayout
android:layout_width="match_parent"
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/layout/activity_main_kotlin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -10,7 +11,9 @@
android:id="@+id/andExoPlayerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
android:layout_weight="1"
app:andexo_show_controller="true"
app:andexo_show_full_screen="true" />

<LinearLayout
android:layout_width="match_parent"
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 22
versionName "2.0.6"
versionCode 23
versionName "2.0.7"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true

Expand Down
62 changes: 58 additions & 4 deletions library/src/main/java/com/potyvideo/library/AndExoPlayerRoot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.google.android.exoplayer2.ui.PlayerView
import com.potyvideo.library.globalEnums.*
import com.potyvideo.library.utils.DoubleClick


abstract class AndExoPlayerRoot @JvmOverloads constructor(
context: Context,
attributeSet: AttributeSet? = null,
Expand All @@ -31,6 +30,9 @@ abstract class AndExoPlayerRoot @JvmOverloads constructor(
var mute: AppCompatImageButton
var unMute: AppCompatImageButton
var settingContainer: FrameLayout
var fullScreenContainer: FrameLayout
var enterFullScreen: AppCompatImageButton
var exitFullScreen: AppCompatImageButton

abstract var customClickListener: DoubleClick

Expand All @@ -40,6 +42,7 @@ abstract class AndExoPlayerRoot @JvmOverloads constructor(
var currResizeMode: EnumResizeMode = EnumResizeMode.FILL
var currMute: EnumMute = EnumMute.UNMUTE
var currPlaybackSpeed: EnumPlaybackSpeed = EnumPlaybackSpeed.NORMAL
var currScreenMode: EnumScreenMode = EnumScreenMode.MINIMISE

init {

Expand All @@ -53,10 +56,12 @@ abstract class AndExoPlayerRoot @JvmOverloads constructor(
mute = playerView.findViewById(R.id.exo_mute)
unMute = playerView.findViewById(R.id.exo_unmute)
settingContainer = playerView.findViewById(R.id.container_setting)
fullScreenContainer = playerView.findViewById(R.id.container_fullscreen)
enterFullScreen = playerView.findViewById(R.id.exo_enter_fullscreen)
exitFullScreen = playerView.findViewById(R.id.exo_exit_fullscreen)

// listeners
initListeners()

}

private fun initListeners() {
Expand All @@ -65,6 +70,9 @@ abstract class AndExoPlayerRoot @JvmOverloads constructor(
forwardView.setOnClickListener(customClickListener)
mute.setOnClickListener(customClickListener)
unMute.setOnClickListener(customClickListener)
fullScreenContainer.setOnClickListener(customClickListener)
enterFullScreen.setOnClickListener(customClickListener)
exitFullScreen.setOnClickListener(customClickListener)
}

protected fun showRetryView() {
Expand All @@ -73,7 +81,6 @@ abstract class AndExoPlayerRoot @JvmOverloads constructor(

protected fun showRetryView(retryTitle: String?) {
retryView.visibility = VISIBLE

if (retryTitle != null)
retryViewTitle.text = retryTitle
}
Expand All @@ -90,6 +97,13 @@ abstract class AndExoPlayerRoot @JvmOverloads constructor(
hideRetryView()
}

protected fun setShowController(showController: Boolean = true) {
if (showController)
showController()
else
hideController()
}

protected fun showController() {
playerView.showController()
}
Expand All @@ -108,11 +122,51 @@ abstract class AndExoPlayerRoot @JvmOverloads constructor(
unMute.visibility = GONE
}

protected fun setShowSetting(showSetting: Boolean = false) {
protected fun setShowSettingButton(showSetting: Boolean = false) {
if (showSetting)
settingContainer.visibility = VISIBLE
else
settingContainer.visibility = GONE
}

protected fun setShowFullScreenButton(showFullscreenButton: Boolean = false) {
if (showFullscreenButton)
fullScreenContainer.visibility = VISIBLE
else
fullScreenContainer.visibility = GONE
}

protected fun setShowScreenModeButton(screenMode: EnumScreenMode = EnumScreenMode.MINIMISE) {
when (screenMode) {
EnumScreenMode.FULLSCREEN -> {
enterFullScreen.visibility = GONE
exitFullScreen.visibility = VISIBLE
}
EnumScreenMode.MINIMISE -> {
enterFullScreen.visibility = VISIBLE
exitFullScreen.visibility = GONE
}
else -> {
enterFullScreen.visibility = VISIBLE
exitFullScreen.visibility = GONE
}
}
}

protected fun showSystemUI() {
playerView.systemUiVisibility = (SYSTEM_UI_FLAG_LOW_PROFILE
or SYSTEM_UI_FLAG_IMMERSIVE
or SYSTEM_UI_FLAG_FULLSCREEN
or SYSTEM_UI_FLAG_LAYOUT_STABLE
or SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or SYSTEM_UI_FLAG_HIDE_NAVIGATION)
}

protected fun hideSystemUI() {
playerView.systemUiVisibility = (SYSTEM_UI_FLAG_LOW_PROFILE
or SYSTEM_UI_FLAG_LAYOUT_STABLE)
}

}
Loading

0 comments on commit 73e0a6b

Please sign in to comment.