Skip to content

Instantly share code, notes, and snippets.

@1nikolas
Created February 3, 2024 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1nikolas/dff206fa7bf41a51c7049b62e63dd0a9 to your computer and use it in GitHub Desktop.
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
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;
}
}
...
<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" />
...
@1nikolas
Copy link
Author

1nikolas commented Feb 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment