Created
February 3, 2024 01:08
-
-
Save 1nikolas/dff206fa7bf41a51c7049b62e63dd0a9 to your computer and use it in GitHub Desktop.
Google Cast Reciever for Android mini controller with 3 buttons and the image at the same time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import androidx.annotation.NonNull; | |
import androidx.annotation.Nullable; | |
import com.google.android.gms.cast.framework.media.ImageHints; | |
import com.google.android.gms.cast.framework.media.uicontroller.UIMediaController; | |
import com.google.android.gms.cast.framework.media.widget.MiniControllerFragment; | |
public class CustomMiniControllerFragment extends MiniControllerFragment { | |
@NonNull | |
@Override | |
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle bundle) { | |
View view = super.onCreateView(inflater, container, bundle); | |
UIMediaController controller = getUIMediaController(); | |
if (controller == null) { | |
return view; | |
} | |
ImageView imageView = view.findViewById(com.google.android.gms.cast.framework.R.id.icon_view); | |
controller.bindImageViewToImageOfCurrentItem(imageView, new ImageHints(2, getResources().getDimensionPixelSize(com.google.android.gms.cast.framework.R.dimen.cast_mini_controller_icon_width), getResources().getDimensionPixelSize(com.google.android.gms.cast.framework.R.dimen.cast_mini_controller_icon_height)), com.google.android.gms.cast.framework.R.drawable.cast_album_art_placeholder); | |
imageView.setVisibility(View.VISIBLE); | |
return view; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<fragment | |
android:id="@+id/castMiniController" | |
class="com.your.package.CustomMiniControllerFragment" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:visibility="gone" | |
app:castControlButtons="@array/cast_mini_controller_control_buttons" <!-- your 3 buttons defined in arrays.xml --> | |
app:castShowImageThumbnail="false" <!-- make sure to set this to false! The image is going to me manually set to visible inside the class --> | |
tools:ignore="FragmentTagUsage" /> | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found a hacky way to do what the library should have allowed in the first place.. Nowadays phone screens are big enough for both an image and 3 buttons.
Hope someone out there finds this useful.