mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
chromecast stuff
This commit is contained in:
parent
90d6f17181
commit
c7d3209736
11 changed files with 206 additions and 14 deletions
|
@ -27,6 +27,10 @@
|
|||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ui.ControllerActivity">
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
|
|
|
@ -177,7 +177,22 @@ object UIHelper {
|
|||
)
|
||||
// window.addFlags(View.KEEP_SCREEN_ON)
|
||||
}
|
||||
fun FragmentActivity.popCurrentPage() {
|
||||
val currentFragment = supportFragmentManager.fragments.lastOrNull {
|
||||
it.isVisible
|
||||
} ?: return
|
||||
|
||||
supportFragmentManager.beginTransaction()
|
||||
.setCustomAnimations(
|
||||
R.anim.enter_anim,
|
||||
R.anim.exit_anim,
|
||||
R.anim.pop_enter,
|
||||
R.anim.pop_exit
|
||||
)
|
||||
.remove(currentFragment)
|
||||
.commitAllowingStateLoss()
|
||||
}
|
||||
/*
|
||||
fun FragmentActivity.popCurrentPage(isInPlayer: Boolean, isInExpandedView: Boolean, isInResults: Boolean) {
|
||||
val currentFragment = supportFragmentManager.fragments.lastOrNull {
|
||||
it.isVisible
|
||||
|
@ -220,7 +235,7 @@ object UIHelper {
|
|||
.commitAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
fun Activity.changeStatusBarState(hide: Boolean): Int {
|
||||
|
|
|
@ -70,6 +70,7 @@ class SelectSourceController(val view: ImageView) : UIController() {
|
|||
super.onMediaStatusUpdated()
|
||||
// If there's 1 item it won't show
|
||||
val dataString = remoteMediaClient.mediaQueue.getItemAtIndex(1)?.media?.customData?.get("data") as? String
|
||||
println("TEXT: " + dataString)
|
||||
view.visibility = if (dataString != null) VISIBLE else INVISIBLE
|
||||
}
|
||||
|
||||
|
@ -84,7 +85,8 @@ class SkipTimeController(val view: ImageView, forwards: Boolean) : UIController(
|
|||
//val settingsManager = PreferenceManager.getDefaultSharedPreferences()
|
||||
//val time = settingsManager?.getInt("chromecast_tap_time", 30) ?: 30
|
||||
val time = 30
|
||||
view.setImageResource(if (forwards) R.drawable.netflix_skip_forward else R.drawable.netflix_skip_back)
|
||||
//view.setImageResource(if (forwards) R.drawable.netflix_skip_forward else R.drawable.netflix_skip_back)
|
||||
view.setImageResource(if (forwards) R.drawable.go_forward_30 else R.drawable.go_back_30)
|
||||
view.setOnClickListener {
|
||||
remoteMediaClient.seek(remoteMediaClient.approximateStreamPosition + time * 1000 * if (forwards) 1 else -1)
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import androidx.appcompat.app.AlertDialog
|
|||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.mediarouter.app.MediaRouteButton
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.transition.Fade
|
||||
import androidx.transition.Transition
|
||||
|
@ -35,6 +36,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper
|
|||
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||
import com.google.android.exoplayer2.*
|
||||
import com.google.android.exoplayer2.C.TIME_UNSET
|
||||
import com.google.android.exoplayer2.ext.cast.CastPlayer
|
||||
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
|
||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
||||
|
@ -42,12 +44,21 @@ import com.google.android.exoplayer2.upstream.DataSource
|
|||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory
|
||||
import com.google.android.exoplayer2.util.MimeTypes
|
||||
import com.google.android.gms.cast.MediaInfo
|
||||
import com.google.android.gms.cast.MediaMetadata
|
||||
import com.google.android.gms.cast.MediaQueueItem
|
||||
import com.google.android.gms.cast.MediaStatus
|
||||
import com.google.android.gms.cast.framework.CastButtonFactory
|
||||
import com.google.android.gms.cast.framework.CastContext
|
||||
import com.google.android.gms.cast.framework.CastState
|
||||
import com.google.android.gms.common.images.WebImage
|
||||
import com.lagradost.cloudstream3.*
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.UIHelper.getFocusRequest
|
||||
import com.lagradost.cloudstream3.UIHelper.getNavigationBarHeight
|
||||
import com.lagradost.cloudstream3.UIHelper.getStatusBarHeight
|
||||
import com.lagradost.cloudstream3.UIHelper.hideSystemUI
|
||||
import com.lagradost.cloudstream3.UIHelper.isCastApiAvailable
|
||||
import com.lagradost.cloudstream3.UIHelper.popCurrentPage
|
||||
import com.lagradost.cloudstream3.UIHelper.requestLocalAudioFocus
|
||||
import com.lagradost.cloudstream3.UIHelper.showSystemUI
|
||||
|
@ -61,8 +72,10 @@ import com.lagradost.cloudstream3.utils.DataStore.setKey
|
|||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||
import com.lagradost.cloudstream3.utils.getId
|
||||
import kotlinx.android.synthetic.main.fragment_player.*
|
||||
import kotlinx.android.synthetic.main.fragment_result.*
|
||||
import kotlinx.android.synthetic.main.player_custom_layout.*
|
||||
import kotlinx.coroutines.*
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
|
@ -404,6 +417,7 @@ class PlayerFragment : Fragment() {
|
|||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
if (!isValidTouch) return
|
||||
isValidTouch = false
|
||||
val transition: Transition = Fade()
|
||||
transition.duration = 1000
|
||||
|
||||
|
@ -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<Int, ArrayList<ExtractorLink>> = HashMap()
|
||||
private var episodes: ArrayList<ResultEpisode> = 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
|
||||
|
|
|
@ -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<MediaRouteButton>(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()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<vector android:height="24dp" android:tint="?attr/white"
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M8,5v14l11,-7z"/>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="850.4dp"
|
||||
android:height="850.4dp"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="850.4"
|
||||
android:viewportHeight="850.4">
|
||||
<path
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -36,7 +36,22 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:navGraph="@navigation/mobile_navigation"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toTopOf="@+id/nav_view"
|
||||
android:id="@+id/cast_mini_controller_holder"
|
||||
>
|
||||
<fragment
|
||||
app:castControlButtons="@array/cast_mini_controller_control_buttons"
|
||||
android:id="@+id/cast_mini_controller"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
class="com.google.android.gms.cast.framework.media.widget.MiniControllerFragment"
|
||||
tools:ignore="FragmentTagUsage">
|
||||
</fragment>
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
|
@ -172,6 +172,19 @@
|
|||
</ImageView>
|
||||
</androidx.cardview.widget.CardView>
|
||||
</LinearLayout>-->
|
||||
|
||||
|
||||
<androidx.mediarouter.app.MediaRouteButton
|
||||
android:layout_margin="5dp"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:id="@+id/player_media_route_button"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:mediaRouteTypes="user"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
<FrameLayout
|
||||
android:id="@+id/video_go_back_holder2"
|
||||
android:layout_margin="5dp"
|
||||
|
@ -197,8 +210,8 @@
|
|||
android:clickable="true"
|
||||
android:background="@drawable/video_tap_button_always_white">
|
||||
</ImageView>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
|
|
16
app/src/main/res/values/array.xml
Normal file
16
app/src/main/res/values/array.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<array name="cast_mini_controller_control_buttons">
|
||||
<item>@id/cast_button_type_rewind_30_seconds</item>
|
||||
<item>@id/cast_button_type_play_pause_toggle</item>
|
||||
<item>@id/cast_button_type_forward_30_seconds</item>
|
||||
</array>
|
||||
<array name="cast_expanded_controller_control_buttons">
|
||||
<!-- Fake sources button -->
|
||||
<item>@id/cast_button_type_rewind_30_seconds</item>
|
||||
<item>@id/cast_button_type_rewind_30_seconds</item>
|
||||
<item>@id/cast_button_type_forward_30_seconds</item>
|
||||
<!-- Actually fake to make the skip op button the same style -->
|
||||
<item>@id/cast_button_type_forward_30_seconds</item>
|
||||
</array>
|
||||
</resources>
|
|
@ -28,6 +28,11 @@
|
|||
<item name="searchViewStyle">@style/AppSearchViewStyle</item>
|
||||
<item name="tabStyle">@style/Theme.Widget.Tabs</item>
|
||||
|
||||
<item name="castExpandedControllerStyle">
|
||||
@style/CustomCastExpandedController
|
||||
</item>
|
||||
<item name="castMiniControllerStyle">@style/CustomCastMiniController</item>
|
||||
|
||||
<!-- DEF STYLE -->
|
||||
<item name="textColor">@color/textColor</item>
|
||||
<item name="colorItemSeen">@color/colorItemSeen</item>
|
||||
|
@ -108,4 +113,42 @@
|
|||
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
|
||||
<item name="android:windowBackground">@drawable/dialog__window_background</item>
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
<!-- CHROMECAST -->
|
||||
<style name="CustomCastExpandedController" parent="CastExpandedController">
|
||||
<item name="castControlButtons">
|
||||
@array/cast_expanded_controller_control_buttons
|
||||
</item>
|
||||
<item name="castButtonColor">@null</item>
|
||||
<item name="castSeekBarProgressAndThumbColor">@color/white</item>
|
||||
<item name="castSeekBarSecondaryProgressColor">?attr/darkBackground</item> <!--CHECK-->
|
||||
<item name="castBackground">?attr/colorPrimary</item>
|
||||
<item name="castProgressBarColor">?attr/colorPrimary</item>
|
||||
<item name="castPlayButtonDrawable">@drawable/ic_baseline_play_arrow_24</item>
|
||||
<item name="castPauseButtonDrawable">@drawable/netflix_pause</item>
|
||||
<item name="castStopButtonDrawable">@drawable/cast_ic_expanded_controller_stop</item>
|
||||
<item name="castSkipPreviousButtonDrawable">@drawable/cast_ic_expanded_controller_skip_previous</item>
|
||||
<item name="castSkipNextButtonDrawable">@drawable/cast_ic_expanded_controller_skip_next</item>
|
||||
<item name="castRewind30ButtonDrawable">@drawable/go_back_30</item>
|
||||
<item name="castForward30ButtonDrawable">@drawable/go_forward_30</item>
|
||||
</style>
|
||||
<style name="CustomCastMiniController" parent="CastMiniController">
|
||||
<item name="castMiniControllerLoadingIndicatorColor">?attr/colorPrimary</item>
|
||||
<item name="castShowImageThumbnail">true</item>
|
||||
|
||||
<item name="castTitleTextAppearance">@style/TextAppearance.AppCompat.Subhead</item>
|
||||
<item name="castSubtitleTextAppearance">@style/TextAppearance.AppCompat.Caption</item>
|
||||
<item name="castBackground">?attr/darkBackground</item> <!--CHECK-->
|
||||
<item name="castProgressBarColor">?attr/colorPrimary</item>
|
||||
<item name="castStopButtonDrawable">@drawable/cast_ic_mini_controller_stop</item>'
|
||||
<item name="castLargeStopButtonDrawable">@drawable/cast_ic_mini_controller_stop_large</item>
|
||||
<item name="castSkipPreviousButtonDrawable">@drawable/cast_ic_mini_controller_skip_prev</item>
|
||||
<item name="castSkipNextButtonDrawable">@drawable/cast_ic_mini_controller_skip_next</item>
|
||||
<item name="castRewind30ButtonDrawable">@drawable/go_back_30</item>
|
||||
<item name="castForward30ButtonDrawable">@drawable/go_forward_30</item>
|
||||
<item name="castMuteToggleButtonDrawable">@drawable/cast_ic_mini_controller_mute</item>
|
||||
<item name="castClosedCaptionsButtonDrawable">@drawable/cast_ic_mini_controller_closed_caption</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Reference in a new issue