parent
999e882af3
commit
b795f4458a
|
|
@ -39,7 +39,7 @@ class VersionActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(), OnT
|
||||||
|
|
||||||
|
|
||||||
// For Testing
|
// For Testing
|
||||||
val shouldShowDebug = false//BuildConfig.DEBUG
|
val shouldShowDebug = true//BuildConfig.DEBUG
|
||||||
llTesting.isVisible = shouldShowDebug
|
llTesting.isVisible = shouldShowDebug
|
||||||
if (shouldShowDebug) {
|
if (shouldShowDebug) {
|
||||||
butCash.setOnClickListener {
|
butCash.setOnClickListener {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import android.view.animation.Animation
|
||||||
import android.view.animation.AnimationSet
|
import android.view.animation.AnimationSet
|
||||||
import android.view.animation.ScaleAnimation
|
import android.view.animation.ScaleAnimation
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.annotation.NonNull
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.ama.core.architecture.appBase.AppViewsEmptyViewModelFragment
|
import com.ama.core.architecture.appBase.AppViewsEmptyViewModelFragment
|
||||||
import com.ama.core.architecture.util.AndroidUtil
|
import com.ama.core.architecture.util.AndroidUtil
|
||||||
|
|
@ -28,8 +27,6 @@ import com.gamedog.vididin.youtubestatistic.TickerTimer
|
||||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.PlayerConstants
|
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.PlayerConstants
|
||||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer
|
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer
|
||||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener
|
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener
|
||||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.YouTubePlayerCallback
|
|
||||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.utils.loadOrCueVideo
|
|
||||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.options.IFramePlayerOptions
|
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.options.IFramePlayerOptions
|
||||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
|
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
|
||||||
import com.viddin.videos.free.databinding.VididinappFeatureHomeItemLayoutBinding as ViewBinding
|
import com.viddin.videos.free.databinding.VididinappFeatureHomeItemLayoutBinding as ViewBinding
|
||||||
|
|
@ -192,7 +189,6 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
||||||
mPlayer = youTubePlayer
|
mPlayer = youTubePlayer
|
||||||
val playerUiController = MyPlayerControlView(mPlayerView!!)
|
val playerUiController = MyPlayerControlView(mPlayerView!!)
|
||||||
mPlayerView!!.setCustomPlayerUi(playerUiController.rootView)
|
mPlayerView!!.setCustomPlayerUi(playerUiController.rootView)
|
||||||
|
|
||||||
if (mPendingPlay) {
|
if (mPendingPlay) {
|
||||||
mPlayer?.loadVideo(mVideoData!!.id, mCurPlayedSecond)
|
mPlayer?.loadVideo(mVideoData!!.id, mCurPlayedSecond)
|
||||||
} else if (mIsPreloading) {
|
} else if (mIsPreloading) {
|
||||||
|
|
@ -392,7 +388,6 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
||||||
|
|
||||||
|
|
||||||
private fun hidePlayIconAnim() {
|
private fun hidePlayIconAnim() {
|
||||||
return
|
|
||||||
if (!binding?.playIcon!!.isVisible) {
|
if (!binding?.playIcon!!.isVisible) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -400,7 +395,7 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
||||||
|
|
||||||
with (binding?.playIcon!!) {
|
with (binding?.playIcon!!) {
|
||||||
val animationSet = AnimationSet(true)
|
val animationSet = AnimationSet(true)
|
||||||
animationSet.duration = 250
|
animationSet.duration = 100
|
||||||
val alphaAnimation = AlphaAnimation(0.6f, 0.3f)
|
val alphaAnimation = AlphaAnimation(0.6f, 0.3f)
|
||||||
val scaleAnimation = ScaleAnimation(
|
val scaleAnimation = ScaleAnimation(
|
||||||
1.0f, 0.5f,
|
1.0f, 0.5f,
|
||||||
|
|
@ -428,12 +423,11 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showPlayIconAnim() {
|
private fun showPlayIconAnim() {
|
||||||
return
|
|
||||||
with (binding?.playIcon!!) {
|
with (binding?.playIcon!!) {
|
||||||
visibility = View.VISIBLE
|
visibility = View.VISIBLE
|
||||||
|
|
||||||
val animationSet = AnimationSet(true)
|
val animationSet = AnimationSet(true)
|
||||||
animationSet.duration = 250
|
animationSet.duration = 100
|
||||||
val alphaAnimation = AlphaAnimation(0.3f, 0.6f)
|
val alphaAnimation = AlphaAnimation(0.3f, 0.6f)
|
||||||
val scaleAnimation = ScaleAnimation(
|
val scaleAnimation = ScaleAnimation(
|
||||||
0.5f, 1.0f,
|
0.5f, 1.0f,
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 6.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB |
|
|
@ -11,7 +11,7 @@ import org.json.JSONObject
|
||||||
class IFramePlayerOptions private constructor(private val playerOptions: JSONObject) {
|
class IFramePlayerOptions private constructor(private val playerOptions: JSONObject) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun getDefault(context: Context) = Builder(context).controls(1).build()
|
fun getDefault(context: Context) = Builder(context).controls(0).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
|
|
||||||
|
|
@ -37,23 +37,89 @@
|
||||||
var player;
|
var player;
|
||||||
|
|
||||||
var timerId;
|
var timerId;
|
||||||
|
function hideYouTubeUI() {
|
||||||
|
setInterval(() => {
|
||||||
|
const playerIFrame = document.querySelector("iframe");
|
||||||
|
if (!playerIFrame) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const frameDoc = playerIFrame.contentDocument || playerIFrame.contentWindow.document;
|
||||||
|
if (!frameDoc) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectorsToHide = [
|
||||||
|
'.ytp-chrome-top',
|
||||||
|
'.ytp-chrome-bottom',
|
||||||
|
'.ytp-gradient-top',
|
||||||
|
'.ytp-gradient-bottom',
|
||||||
|
'.ytp-youtube-button',
|
||||||
|
'.ytp-watermark',
|
||||||
|
'.ytp-ce-element',
|
||||||
|
'.ytp-paid-content-overlay',
|
||||||
|
'.ytp-bezel-container',
|
||||||
|
'.ytp-spinner',
|
||||||
|
'.ytp-cards-teaser',
|
||||||
|
'.ytp-cards-button',
|
||||||
|
'.ytp-show-cards-title'
|
||||||
|
];
|
||||||
|
|
||||||
|
selectorsToHide.forEach(selector => {
|
||||||
|
const elements = frameDoc.querySelectorAll(selector);
|
||||||
|
elements.forEach(el => {
|
||||||
|
if (el.style.display !== 'none') {
|
||||||
|
el.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Special handling for pause overlays to avoid black screen issue
|
||||||
|
const pauseOverlays = ['.ytp-pause-overlay', '.ytp-pause-overlay-container'];
|
||||||
|
pauseOverlays.forEach(selector => {
|
||||||
|
const elements = frameDoc.querySelectorAll(selector);
|
||||||
|
elements.forEach(el => {
|
||||||
|
if (el.style.visibility !== 'hidden') {
|
||||||
|
el.style.visibility = 'hidden';
|
||||||
|
el.style.pointerEvents = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (player && typeof player.unloadModule === 'function') {
|
||||||
|
player.unloadModule('captions');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable captions if any
|
||||||
|
const captions = frameDoc.querySelector('.ytp-caption-window-container');
|
||||||
|
if (captions) {
|
||||||
|
captions.style.display = 'none';
|
||||||
|
}
|
||||||
|
}, 50);
|
||||||
|
}
|
||||||
function onYouTubeIframeAPIReady() {
|
function onYouTubeIframeAPIReady() {
|
||||||
|
|
||||||
YouTubePlayerBridge.sendYouTubeIFrameAPIReady();
|
YouTubePlayerBridge.sendYouTubeIFrameAPIReady();
|
||||||
|
|
||||||
|
var playerVars = <<injectedPlayerVars>>;
|
||||||
|
// Force some player vars to hide UI elements at the API level
|
||||||
|
// but avoid overriding everything to stay compatible
|
||||||
|
playerVars.rel = 0;
|
||||||
|
playerVars.iv_load_policy = 3;
|
||||||
|
playerVars.modestbranding = 1;
|
||||||
|
|
||||||
var youtubePlayerConfig = {
|
var youtubePlayerConfig = {
|
||||||
height: '100%',
|
height: '100%',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
events: {
|
events: {
|
||||||
onReady: function(event) { YouTubePlayerBridge.sendReady() },
|
onReady: function(event) { YouTubePlayerBridge.sendReady();hideYouTubeUI(); },
|
||||||
onStateChange: function(event) { sendPlayerStateChange(event.data) },
|
onStateChange: function(event) { sendPlayerStateChange(event.data) },
|
||||||
onPlaybackQualityChange: function(event) { YouTubePlayerBridge.sendPlaybackQualityChange(event.data) },
|
onPlaybackQualityChange: function(event) { YouTubePlayerBridge.sendPlaybackQualityChange(event.data) },
|
||||||
onPlaybackRateChange: function(event) { YouTubePlayerBridge.sendPlaybackRateChange(event.data) },
|
onPlaybackRateChange: function(event) { YouTubePlayerBridge.sendPlaybackRateChange(event.data) },
|
||||||
onError: function(error) { YouTubePlayerBridge.sendError(error.data) },
|
onError: function(error) { YouTubePlayerBridge.sendError(error.data) },
|
||||||
onApiChange: function(event) { YouTubePlayerBridge.sendApiChange() }
|
onApiChange: function(event) { YouTubePlayerBridge.sendApiChange() }
|
||||||
},
|
},
|
||||||
playerVars: <<injectedPlayerVars>>
|
playerVars: playerVars
|
||||||
};
|
};
|
||||||
|
|
||||||
if (<<injectedVideoId>>) {
|
if (<<injectedVideoId>>) {
|
||||||
|
|
|
||||||
|
|
@ -21,269 +21,285 @@ import com.pierfrancescosoffritti.androidyoutubeplayer.core.customui.views.YouTu
|
||||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.customui.views.YouTubePlayerSeekBarListener
|
import com.pierfrancescosoffritti.androidyoutubeplayer.core.customui.views.YouTubePlayerSeekBarListener
|
||||||
|
|
||||||
class DefaultPlayerUiController(
|
class DefaultPlayerUiController(
|
||||||
private val youTubePlayerView: YouTubePlayerView,
|
private val youTubePlayerView: YouTubePlayerView,
|
||||||
private val youTubePlayer: YouTubePlayer
|
private val youTubePlayer: YouTubePlayer
|
||||||
) : PlayerUiController {
|
) : PlayerUiController {
|
||||||
|
|
||||||
val rootView: View = View.inflate(youTubePlayerView.context, R.layout.ayp_default_player_ui, null)
|
val rootView: View =
|
||||||
|
View.inflate(youTubePlayerView.context, R.layout.ayp_default_player_ui, null)
|
||||||
|
|
||||||
private var youTubePlayerMenu: YouTubePlayerMenu = DefaultYouTubePlayerMenu(
|
private var youTubePlayerMenu: YouTubePlayerMenu = DefaultYouTubePlayerMenu(
|
||||||
youTubePlayerView.context
|
youTubePlayerView.context
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View used for for intercepting clicks and for drawing a black background.
|
* View used for for intercepting clicks and for drawing a black background.
|
||||||
* Could have used controlsContainer, but in this way I'm able to hide all the control at once by hiding controlsContainer
|
* Could have used controlsContainer, but in this way I'm able to hide all the control at once by hiding controlsContainer
|
||||||
*/
|
*/
|
||||||
private val panel: View = rootView.findViewById(R.id.panel)
|
private val panel: View = rootView.findViewById(R.id.panel)
|
||||||
|
|
||||||
private val controlsContainer: View = rootView.findViewById(R.id.controls_container)
|
private val controlsContainer: View = rootView.findViewById(R.id.controls_container)
|
||||||
private val extraViewsContainer: LinearLayout = rootView.findViewById(R.id.extra_views_container)
|
private val extraViewsContainer: LinearLayout =
|
||||||
|
rootView.findViewById(R.id.extra_views_container)
|
||||||
|
|
||||||
private val videoTitle: TextView = rootView.findViewById(R.id.video_title)
|
private val videoTitle: TextView = rootView.findViewById(R.id.video_title)
|
||||||
private val liveVideoIndicator: TextView = rootView.findViewById(R.id.live_video_indicator)
|
private val liveVideoIndicator: TextView = rootView.findViewById(R.id.live_video_indicator)
|
||||||
|
|
||||||
private val progressBar: ProgressBar = rootView.findViewById(R.id.progress)
|
private val progressBar: ProgressBar = rootView.findViewById(R.id.progress)
|
||||||
private val menuButton: ImageView = rootView.findViewById(R.id.menu_button)
|
private val menuButton: ImageView = rootView.findViewById(R.id.menu_button)
|
||||||
private val playPauseButton: ImageView = rootView.findViewById(R.id.play_pause_button)
|
private val playPauseButton: ImageView = rootView.findViewById(R.id.play_pause_button)
|
||||||
private val youTubeButton: ImageView = rootView.findViewById(R.id.youtube_button)
|
private val youTubeButton: ImageView = rootView.findViewById(R.id.youtube_button)
|
||||||
private val fullscreenButton: ImageView = rootView.findViewById(R.id.fullscreen_button)
|
private val fullscreenButton: ImageView = rootView.findViewById(R.id.fullscreen_button)
|
||||||
|
|
||||||
private val customActionLeft: ImageView = rootView.findViewById(R.id.custom_action_left_button)
|
private val customActionLeft: ImageView = rootView.findViewById(R.id.custom_action_left_button)
|
||||||
private val customActionRight: ImageView = rootView.findViewById(R.id.custom_action_right_button)
|
private val customActionRight: ImageView =
|
||||||
|
rootView.findViewById(R.id.custom_action_right_button)
|
||||||
|
|
||||||
private val youtubePlayerSeekBar: YouTubePlayerSeekBar = rootView.findViewById(R.id.youtube_player_seekbar)
|
private val youtubePlayerSeekBar: YouTubePlayerSeekBar =
|
||||||
private val fadeControlsContainer: FadeViewHelper = FadeViewHelper(controlsContainer)
|
rootView.findViewById(R.id.youtube_player_seekbar)
|
||||||
|
private val fadeControlsContainer: FadeViewHelper = FadeViewHelper(controlsContainer)
|
||||||
|
|
||||||
private var onFullscreenButtonListener: View.OnClickListener
|
private var onFullscreenButtonListener: View.OnClickListener
|
||||||
private var onMenuButtonClickListener: View.OnClickListener
|
private var onMenuButtonClickListener: View.OnClickListener
|
||||||
|
|
||||||
private var isPlaying = false
|
private var isPlaying = false
|
||||||
private var isPlayPauseButtonEnabled = true
|
private var isPlayPauseButtonEnabled = true
|
||||||
private var isCustomActionLeftEnabled = false
|
private var isCustomActionLeftEnabled = false
|
||||||
private var isCustomActionRightEnabled = false
|
private var isCustomActionRightEnabled = false
|
||||||
|
|
||||||
private var isMatchParent = false
|
private var isMatchParent = false
|
||||||
|
|
||||||
private val youTubePlayerStateListener = object : AbstractYouTubePlayerListener() {
|
private val youTubePlayerStateListener = object : AbstractYouTubePlayerListener() {
|
||||||
override fun onStateChange(youTubePlayer: YouTubePlayer, state: PlayerConstants.PlayerState) {
|
override fun onStateChange(
|
||||||
updateState(state)
|
youTubePlayer: YouTubePlayer,
|
||||||
|
state: PlayerConstants.PlayerState
|
||||||
|
) {
|
||||||
|
updateState(state)
|
||||||
|
|
||||||
if (state === PlayerConstants.PlayerState.PLAYING || state === PlayerConstants.PlayerState.PAUSED || state === PlayerConstants.PlayerState.VIDEO_CUED) {
|
if (state === PlayerConstants.PlayerState.PLAYING || state === PlayerConstants.PlayerState.PAUSED || state === PlayerConstants.PlayerState.VIDEO_CUED) {
|
||||||
panel.setBackgroundColor(ContextCompat.getColor(panel.context, android.R.color.transparent))
|
panel.setBackgroundColor(
|
||||||
progressBar.visibility = View.GONE
|
ContextCompat.getColor(
|
||||||
|
panel.context,
|
||||||
|
android.R.color.transparent
|
||||||
|
)
|
||||||
|
)
|
||||||
|
progressBar.visibility = View.GONE
|
||||||
|
|
||||||
if (isPlayPauseButtonEnabled) playPauseButton.visibility = View.VISIBLE
|
if (isPlayPauseButtonEnabled) playPauseButton.visibility = View.VISIBLE
|
||||||
if (isCustomActionLeftEnabled) customActionLeft.visibility = View.VISIBLE
|
if (isCustomActionLeftEnabled) customActionLeft.visibility = View.VISIBLE
|
||||||
if (isCustomActionRightEnabled) customActionRight.visibility = View.VISIBLE
|
if (isCustomActionRightEnabled) customActionRight.visibility = View.VISIBLE
|
||||||
|
|
||||||
updatePlayPauseButtonIcon(state === PlayerConstants.PlayerState.PLAYING)
|
updatePlayPauseButtonIcon(state === PlayerConstants.PlayerState.PLAYING)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
updatePlayPauseButtonIcon(false)
|
updatePlayPauseButtonIcon(false)
|
||||||
|
|
||||||
if (state === PlayerConstants.PlayerState.BUFFERING) {
|
if (state === PlayerConstants.PlayerState.BUFFERING) {
|
||||||
progressBar.visibility = View.VISIBLE
|
// progressBar.visibility = View.VISIBLE
|
||||||
panel.setBackgroundColor(
|
progressBar.visibility = View.GONE
|
||||||
ContextCompat.getColor(
|
panel.setBackgroundColor(
|
||||||
panel.context,
|
ContextCompat.getColor(
|
||||||
android.R.color.transparent
|
panel.context,
|
||||||
)
|
android.R.color.transparent
|
||||||
)
|
)
|
||||||
if (isPlayPauseButtonEnabled) playPauseButton.visibility = View.INVISIBLE
|
)
|
||||||
|
if (isPlayPauseButtonEnabled) playPauseButton.visibility = View.INVISIBLE
|
||||||
|
|
||||||
customActionLeft.visibility = View.GONE
|
customActionLeft.visibility = View.GONE
|
||||||
customActionRight.visibility = View.GONE
|
customActionRight.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state === PlayerConstants.PlayerState.UNSTARTED) {
|
||||||
|
progressBar.visibility = View.GONE
|
||||||
|
if (isPlayPauseButtonEnabled) playPauseButton.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state === PlayerConstants.PlayerState.UNSTARTED) {
|
override fun onVideoId(youTubePlayer: YouTubePlayer, videoId: String) {
|
||||||
progressBar.visibility = View.GONE
|
youTubeButton.setOnClickListener {
|
||||||
if (isPlayPauseButtonEnabled) playPauseButton.visibility = View.VISIBLE
|
val intent = Intent(
|
||||||
|
Intent.ACTION_VIEW,
|
||||||
|
Uri.parse("https://www.youtube.com/watch?v=" + videoId + "#t=" + youtubePlayerSeekBar.seekBar.progress)
|
||||||
|
)
|
||||||
|
try {
|
||||||
|
youTubeButton.context.startActivity(intent)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(javaClass.simpleName, e.message ?: "Can't open url to YouTube")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onVideoId(youTubePlayer: YouTubePlayer, videoId: String) {
|
init {
|
||||||
youTubeButton.setOnClickListener {
|
onFullscreenButtonListener = View.OnClickListener {
|
||||||
val intent = Intent(
|
isMatchParent = !isMatchParent
|
||||||
Intent.ACTION_VIEW,
|
when (isMatchParent) {
|
||||||
Uri.parse("https://www.youtube.com/watch?v=" + videoId + "#t=" + youtubePlayerSeekBar.seekBar.progress)
|
true -> youTubePlayerView.matchParent()
|
||||||
)
|
false -> youTubePlayerView.wrapContent()
|
||||||
try {
|
}
|
||||||
youTubeButton.context.startActivity(intent)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(javaClass.simpleName, e.message ?: "Can't open url to YouTube")
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
onMenuButtonClickListener = View.OnClickListener { youTubePlayerMenu.show(menuButton) }
|
||||||
onFullscreenButtonListener = View.OnClickListener {
|
|
||||||
isMatchParent = !isMatchParent
|
initClickListeners()
|
||||||
when (isMatchParent) {
|
|
||||||
true -> youTubePlayerView.matchParent()
|
|
||||||
false -> youTubePlayerView.wrapContent()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMenuButtonClickListener = View.OnClickListener { youTubePlayerMenu.show(menuButton) }
|
private fun initClickListeners() {
|
||||||
|
fadeControlsContainer.isDisabled = true
|
||||||
|
youTubePlayer.addListener(youtubePlayerSeekBar)
|
||||||
|
youTubePlayer.addListener(fadeControlsContainer)
|
||||||
|
youTubePlayer.addListener(youTubePlayerStateListener)
|
||||||
|
|
||||||
initClickListeners()
|
youtubePlayerSeekBar.youtubePlayerSeekBarListener = object : YouTubePlayerSeekBarListener {
|
||||||
}
|
override fun seekTo(time: Float) = youTubePlayer.seekTo(time)
|
||||||
|
}
|
||||||
private fun initClickListeners() {
|
panel.setOnClickListener { fadeControlsContainer.toggleVisibility() }
|
||||||
youTubePlayer.addListener(youtubePlayerSeekBar)
|
playPauseButton.setOnClickListener { onPlayButtonPressed() }
|
||||||
youTubePlayer.addListener(fadeControlsContainer)
|
fullscreenButton.setOnClickListener { onFullscreenButtonListener.onClick(fullscreenButton) }
|
||||||
youTubePlayer.addListener(youTubePlayerStateListener)
|
menuButton.setOnClickListener { onMenuButtonClickListener.onClick(menuButton) }
|
||||||
|
|
||||||
youtubePlayerSeekBar.youtubePlayerSeekBarListener = object : YouTubePlayerSeekBarListener {
|
|
||||||
override fun seekTo(time: Float) = youTubePlayer.seekTo(time)
|
|
||||||
}
|
|
||||||
panel.setOnClickListener { fadeControlsContainer.toggleVisibility() }
|
|
||||||
playPauseButton.setOnClickListener { onPlayButtonPressed() }
|
|
||||||
fullscreenButton.setOnClickListener { onFullscreenButtonListener.onClick(fullscreenButton) }
|
|
||||||
menuButton.setOnClickListener { onMenuButtonClickListener.onClick(menuButton) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showVideoTitle(show: Boolean): PlayerUiController {
|
|
||||||
videoTitle.visibility = if (show) View.VISIBLE else View.GONE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setVideoTitle(videoTitle: String): PlayerUiController {
|
|
||||||
this.videoTitle.text = videoTitle
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showUi(show: Boolean): PlayerUiController {
|
|
||||||
fadeControlsContainer.isDisabled = !show
|
|
||||||
controlsContainer.visibility = if (show) View.VISIBLE else View.INVISIBLE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showPlayPauseButton(show: Boolean): PlayerUiController {
|
|
||||||
playPauseButton.visibility = if (show) View.VISIBLE else View.GONE
|
|
||||||
|
|
||||||
isPlayPauseButtonEnabled = show
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun enableLiveVideoUi(enable: Boolean): PlayerUiController {
|
|
||||||
youtubePlayerSeekBar.visibility = if (enable) View.INVISIBLE else View.VISIBLE
|
|
||||||
liveVideoIndicator.visibility = if (enable) View.VISIBLE else View.GONE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setCustomAction1(
|
|
||||||
icon: Drawable,
|
|
||||||
clickListener: View.OnClickListener?
|
|
||||||
): PlayerUiController {
|
|
||||||
customActionLeft.setImageDrawable(icon)
|
|
||||||
customActionLeft.setOnClickListener(clickListener)
|
|
||||||
showCustomAction1(true)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setCustomAction2(
|
|
||||||
icon: Drawable,
|
|
||||||
clickListener: View.OnClickListener?
|
|
||||||
): PlayerUiController {
|
|
||||||
customActionRight.setImageDrawable(icon)
|
|
||||||
customActionRight.setOnClickListener(clickListener)
|
|
||||||
showCustomAction2(true)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showCustomAction1(show: Boolean): PlayerUiController {
|
|
||||||
isCustomActionLeftEnabled = show
|
|
||||||
customActionLeft.visibility = if (show) View.VISIBLE else View.GONE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showCustomAction2(show: Boolean): PlayerUiController {
|
|
||||||
isCustomActionRightEnabled = show
|
|
||||||
customActionRight.visibility = if (show) View.VISIBLE else View.GONE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showMenuButton(show: Boolean): PlayerUiController {
|
|
||||||
menuButton.visibility = if (show) View.VISIBLE else View.GONE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setMenuButtonClickListener(customMenuButtonClickListener: View.OnClickListener): PlayerUiController {
|
|
||||||
onMenuButtonClickListener = customMenuButtonClickListener
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showCurrentTime(show: Boolean): PlayerUiController {
|
|
||||||
youtubePlayerSeekBar.videoCurrentTimeTextView.visibility = if (show) View.VISIBLE else View.GONE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showDuration(show: Boolean): PlayerUiController {
|
|
||||||
youtubePlayerSeekBar.videoDurationTextView.visibility = if (show) View.VISIBLE else View.GONE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showSeekBar(show: Boolean): PlayerUiController {
|
|
||||||
youtubePlayerSeekBar.seekBar.visibility = if (show) View.VISIBLE else View.INVISIBLE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showBufferingProgress(show: Boolean): PlayerUiController {
|
|
||||||
youtubePlayerSeekBar.showBufferingProgress = show
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showYouTubeButton(show: Boolean): PlayerUiController {
|
|
||||||
youTubeButton.visibility = if (show) View.VISIBLE else View.GONE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun addView(view: View): PlayerUiController {
|
|
||||||
extraViewsContainer.addView(view, 0)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun removeView(view: View): PlayerUiController {
|
|
||||||
extraViewsContainer.removeView(view)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getMenu(): YouTubePlayerMenu = youTubePlayerMenu
|
|
||||||
|
|
||||||
override fun showFullscreenButton(show: Boolean): PlayerUiController {
|
|
||||||
fullscreenButton.visibility = if (show) View.VISIBLE else View.GONE
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setFullscreenButtonClickListener(customFullscreenButtonClickListener: View.OnClickListener): PlayerUiController {
|
|
||||||
onFullscreenButtonListener = customFullscreenButtonClickListener
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onPlayButtonPressed() {
|
|
||||||
if (isPlaying)
|
|
||||||
youTubePlayer.pause()
|
|
||||||
else
|
|
||||||
youTubePlayer.play()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateState(state: PlayerConstants.PlayerState) {
|
|
||||||
when (state) {
|
|
||||||
PlayerConstants.PlayerState.ENDED -> isPlaying = false
|
|
||||||
PlayerConstants.PlayerState.PAUSED -> isPlaying = false
|
|
||||||
PlayerConstants.PlayerState.PLAYING -> isPlaying = true
|
|
||||||
else -> {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePlayPauseButtonIcon(!isPlaying)
|
override fun showVideoTitle(show: Boolean): PlayerUiController {
|
||||||
}
|
videoTitle.visibility = if (show) View.VISIBLE else View.GONE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
private fun updatePlayPauseButtonIcon(playing: Boolean) {
|
override fun setVideoTitle(videoTitle: String): PlayerUiController {
|
||||||
val drawable = if (playing) R.drawable.ayp_ic_pause_36dp else R.drawable.ayp_ic_play_36dp
|
this.videoTitle.text = videoTitle
|
||||||
playPauseButton.setImageResource(drawable)
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun showUi(show: Boolean): PlayerUiController {
|
||||||
|
fadeControlsContainer.isDisabled = !show
|
||||||
|
controlsContainer.visibility = if (show) View.VISIBLE else View.INVISIBLE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showPlayPauseButton(show: Boolean): PlayerUiController {
|
||||||
|
playPauseButton.visibility = if (show) View.VISIBLE else View.GONE
|
||||||
|
|
||||||
|
isPlayPauseButtonEnabled = show
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun enableLiveVideoUi(enable: Boolean): PlayerUiController {
|
||||||
|
youtubePlayerSeekBar.visibility = if (enable) View.INVISIBLE else View.VISIBLE
|
||||||
|
liveVideoIndicator.visibility = if (enable) View.VISIBLE else View.GONE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setCustomAction1(
|
||||||
|
icon: Drawable,
|
||||||
|
clickListener: View.OnClickListener?
|
||||||
|
): PlayerUiController {
|
||||||
|
customActionLeft.setImageDrawable(icon)
|
||||||
|
customActionLeft.setOnClickListener(clickListener)
|
||||||
|
showCustomAction1(true)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setCustomAction2(
|
||||||
|
icon: Drawable,
|
||||||
|
clickListener: View.OnClickListener?
|
||||||
|
): PlayerUiController {
|
||||||
|
customActionRight.setImageDrawable(icon)
|
||||||
|
customActionRight.setOnClickListener(clickListener)
|
||||||
|
showCustomAction2(true)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showCustomAction1(show: Boolean): PlayerUiController {
|
||||||
|
isCustomActionLeftEnabled = show
|
||||||
|
customActionLeft.visibility = if (show) View.VISIBLE else View.GONE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showCustomAction2(show: Boolean): PlayerUiController {
|
||||||
|
isCustomActionRightEnabled = show
|
||||||
|
customActionRight.visibility = if (show) View.VISIBLE else View.GONE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showMenuButton(show: Boolean): PlayerUiController {
|
||||||
|
menuButton.visibility = if (show) View.VISIBLE else View.GONE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setMenuButtonClickListener(customMenuButtonClickListener: View.OnClickListener): PlayerUiController {
|
||||||
|
onMenuButtonClickListener = customMenuButtonClickListener
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showCurrentTime(show: Boolean): PlayerUiController {
|
||||||
|
youtubePlayerSeekBar.videoCurrentTimeTextView.visibility =
|
||||||
|
if (show) View.VISIBLE else View.GONE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showDuration(show: Boolean): PlayerUiController {
|
||||||
|
youtubePlayerSeekBar.videoDurationTextView.visibility =
|
||||||
|
if (show) View.VISIBLE else View.GONE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showSeekBar(show: Boolean): PlayerUiController {
|
||||||
|
youtubePlayerSeekBar.seekBar.visibility = if (show) View.VISIBLE else View.INVISIBLE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showBufferingProgress(show: Boolean): PlayerUiController {
|
||||||
|
youtubePlayerSeekBar.showBufferingProgress = show
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showYouTubeButton(show: Boolean): PlayerUiController {
|
||||||
|
youTubeButton.visibility = if (show) View.VISIBLE else View.GONE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addView(view: View): PlayerUiController {
|
||||||
|
extraViewsContainer.addView(view, 0)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun removeView(view: View): PlayerUiController {
|
||||||
|
extraViewsContainer.removeView(view)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getMenu(): YouTubePlayerMenu = youTubePlayerMenu
|
||||||
|
|
||||||
|
override fun showFullscreenButton(show: Boolean): PlayerUiController {
|
||||||
|
fullscreenButton.visibility = if (show) View.VISIBLE else View.GONE
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setFullscreenButtonClickListener(customFullscreenButtonClickListener: View.OnClickListener): PlayerUiController {
|
||||||
|
onFullscreenButtonListener = customFullscreenButtonClickListener
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onPlayButtonPressed() {
|
||||||
|
if (isPlaying)
|
||||||
|
youTubePlayer.pause()
|
||||||
|
else
|
||||||
|
youTubePlayer.play()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateState(state: PlayerConstants.PlayerState) {
|
||||||
|
when (state) {
|
||||||
|
PlayerConstants.PlayerState.ENDED -> isPlaying = false
|
||||||
|
PlayerConstants.PlayerState.PAUSED -> isPlaying = false
|
||||||
|
PlayerConstants.PlayerState.PLAYING -> isPlaying = true
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePlayPauseButtonIcon(!isPlaying)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updatePlayPauseButtonIcon(playing: Boolean) {
|
||||||
|
val drawable = if (playing) R.drawable.ayp_ic_pause_36dp else R.drawable.ayp_ic_play_36dp
|
||||||
|
playPauseButton.setImageResource(drawable)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<View
|
<View
|
||||||
|
|
@ -93,6 +94,7 @@
|
||||||
android:id="@+id/progress"
|
android:id="@+id/progress"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone"
|
||||||
android:layout_centerInParent="true" />
|
android:layout_centerInParent="true" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue