diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c62789a7..e267b893 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -27,6 +27,10 @@ + + + + { if (!isValidTouch) return + isValidTouch = false val transition: Transition = Fade() transition.duration = 1000 @@ -463,7 +477,7 @@ class PlayerFragment : Fragment() { else (data is AnimeLoadResponse && (data.type == TvType.Anime || data.type == TvType.ONA)) skip_op.visibility = if (isVis) View.VISIBLE else View.GONE } else { - if(data is AnimeLoadResponse) { + if (data is AnimeLoadResponse) { val isVis = ((data.type == TvType.Anime || data.type == TvType.ONA)) skip_op_text.text = "Skip OP" skip_op.visibility = if (isVis) View.VISIBLE else View.GONE @@ -562,6 +576,7 @@ class PlayerFragment : Fragment() { skip_op.isClickable = isClick resize_player.isClickable = isClick exo_progress.isEnabled = isClick + player_media_route_button.isEnabled = isClick //video_go_back_holder2.isEnabled = isClick // Clickable doesn't seem to work on com.google.android.exoplayer2.ui.DefaultTimeBar @@ -580,6 +595,7 @@ class PlayerFragment : Fragment() { private var playbackSpeed = 0f private var allEpisodes: HashMap> = HashMap() private var episodes: ArrayList = ArrayList() + var currentPoster: String? = null @SuppressLint("SetTextI18n") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -588,6 +604,67 @@ class PlayerFragment : Fragment() { navigationBarHeight = requireContext().getNavigationBarHeight() statusBarHeight = requireContext().getStatusBarHeight() + if (activity?.isCastApiAvailable() == true) { + CastButtonFactory.setUpMediaRouteButton(activity, player_media_route_button) + val castContext = CastContext.getSharedInstance(requireActivity().applicationContext) + + if (castContext.castState != CastState.NO_DEVICES_AVAILABLE) player_media_route_button.visibility = VISIBLE + castContext.addCastStateListener { state -> + if (player_media_route_button != null) { + if (state == CastState.NO_DEVICES_AVAILABLE) player_media_route_button.visibility = GONE else { + if (player_media_route_button.visibility == GONE) player_media_route_button.visibility = VISIBLE + } + if (state == CastState.CONNECTED) { + if (!this::exoPlayer.isInitialized) return@addCastStateListener + val links = sortUrls(getUrls() ?: return@addCastStateListener) + val epData = getEpisode() ?: return@addCastStateListener + + val index = links.indexOf(getCurrentUrl()) + + val mediaItems = links.map { + val movieMetadata = MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE) + movieMetadata.putString( + MediaMetadata.KEY_TITLE, + + "Episode ${epData.episode}" + + if (epData.name != null) + "- ${epData.name}" + else + "" + ) + movieMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, + epData.name ?: "Episode ${epData.episode}") + + val srcPoster = epData.poster ?: currentPoster + if (srcPoster != null) { + movieMetadata.addImage(WebImage(Uri.parse(srcPoster))) + } + + MediaQueueItem.Builder( + MediaInfo.Builder(it.url) + .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) + .setContentType(MimeTypes.VIDEO_UNKNOWN) + .setCustomData(JSONObject().put("data", it.name)) + .setMetadata(movieMetadata) + .build() + ) + .build() + }.toTypedArray() + + val castPlayer = CastPlayer(castContext) + castPlayer.loadItems( + mediaItems, + if (index > 0) index else 0, + exoPlayer.currentPosition, + MediaStatus.REPEAT_MODE_REPEAT_SINGLE + ) + // activity?.popCurrentPage(isInPlayer = true, isInExpandedView = false, isInResults = false) + activity?.popCurrentPage() + } + } + } + } + if (savedInstanceState != null) { currentWindow = savedInstanceState.getInt(STATE_RESUME_WINDOW) playbackPosition = savedInstanceState.getLong(STATE_RESUME_POSITION) @@ -637,6 +714,7 @@ class PlayerFragment : Fragment() { val d = data.value if (d is LoadResponse) { localData = d + currentPoster = d.posterUrl } } is Resource.Failure -> { @@ -709,6 +787,7 @@ class PlayerFragment : Fragment() { // MENUS centerMenu.startAnimation(fadeAnimation) + player_media_route_button.startAnimation(fadeAnimation) //video_bar.startAnimation(fadeAnimation) //TITLE @@ -759,11 +838,13 @@ class PlayerFragment : Fragment() { ) video_go_back.setOnClickListener { - activity?.popCurrentPage(isInPlayer = true, isInExpandedView = false, isInResults = false) + //activity?.popCurrentPage(isInPlayer = true, isInExpandedView = false, isInResults = false) + activity?.popCurrentPage() } video_go_back_holder.setOnClickListener { println("video_go_back_pressed") - activity?.popCurrentPage(isInPlayer = true, isInExpandedView = false, isInResults = false) + // activity?.popCurrentPage(isInPlayer = true, isInExpandedView = false, isInResults = false) + activity?.popCurrentPage() } playback_speed_btt.visibility = if (playBackSpeedEnabled) VISIBLE else GONE @@ -1146,7 +1227,7 @@ class PlayerFragment : Fragment() { override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) { // updatePIPModeActions() - if(activity == null) return + if (activity == null) return if (playWhenReady) { when (playbackState) { Player.STATE_READY -> { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index 9e6f1bab..33e271c9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -47,6 +47,7 @@ import com.lagradost.cloudstream3.utils.ExtractorLink import jp.wasabeef.glide.transformations.BlurTransformation import kotlinx.android.synthetic.main.fragment_result.* import org.json.JSONObject +import android.app.ProgressDialog const val MAX_SYNO_LENGH = 300 @@ -107,8 +108,6 @@ class ResultFragment : Fragment() { activity?.fixPaddingStatusbar(result_barstatus) if (activity?.isCastApiAvailable() == true) { - val mMediaRouteButton = view.findViewById(R.id.media_route_button) - CastButtonFactory.setUpMediaRouteButton(activity, media_route_button) val castContext = CastContext.getSharedInstance(requireActivity().applicationContext) @@ -151,9 +150,13 @@ class ResultFragment : Fragment() { val buildInPlayer = true when (episodeClick.action) { ACTION_CHROME_CAST_EPISODE -> { + val dialog = ProgressDialog.show(requireContext(), "", + "Loading. Please wait...", true) + dialog.show() Toast.makeText(activity, "Loading links", Toast.LENGTH_SHORT).show() viewModel.loadEpisode(episodeClick.data, true) { data -> + dialog.dismiss() when (data) { is Resource.Failure -> { Toast.makeText(activity, "Failed to load links", Toast.LENGTH_SHORT).show() diff --git a/app/src/main/res/drawable/ic_baseline_play_arrow_24.xml b/app/src/main/res/drawable/ic_baseline_play_arrow_24.xml index f880379f..0870be8f 100644 --- a/app/src/main/res/drawable/ic_baseline_play_arrow_24.xml +++ b/app/src/main/res/drawable/ic_baseline_play_arrow_24.xml @@ -1,4 +1,4 @@ - diff --git a/app/src/main/res/drawable/netflix_play.xml b/app/src/main/res/drawable/netflix_play.xml index 816d1069..1f8c9e7d 100644 --- a/app/src/main/res/drawable/netflix_play.xml +++ b/app/src/main/res/drawable/netflix_play.xml @@ -1,6 +1,6 @@ - + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/player_custom_layout.xml b/app/src/main/res/layout/player_custom_layout.xml index 638d1b2c..d2e58427 100644 --- a/app/src/main/res/layout/player_custom_layout.xml +++ b/app/src/main/res/layout/player_custom_layout.xml @@ -172,6 +172,19 @@ --> + + + - + + + + @id/cast_button_type_rewind_30_seconds + @id/cast_button_type_play_pause_toggle + @id/cast_button_type_forward_30_seconds + + + + @id/cast_button_type_rewind_30_seconds + @id/cast_button_type_rewind_30_seconds + @id/cast_button_type_forward_30_seconds + + @id/cast_button_type_forward_30_seconds + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ce927e25..9a5a0e84 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -28,6 +28,11 @@ @style/AppSearchViewStyle @style/Theme.Widget.Tabs + + @style/CustomCastExpandedController + + @style/CustomCastMiniController + @color/textColor @color/colorItemSeen @@ -108,4 +113,42 @@ @android:dimen/dialog_min_width_minor @drawable/dialog__window_background + + + + + + \ No newline at end of file