Skip to content

Instantly share code, notes, and snippets.

@1nikolas
Created February 3, 2024 01:08
Show Gist options
  • Select an option

  • Save 1nikolas/dff206fa7bf41a51c7049b62e63dd0a9 to your computer and use it in GitHub Desktop.

Select an option

Save 1nikolas/dff206fa7bf41a51c7049b62e63dd0a9 to your computer and use it in GitHub Desktop.

Revisions

  1. 1nikolas created this gist Feb 3, 2024.
    33 changes: 33 additions & 0 deletions CustomMiniControllerFragment.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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;
    }
    }
    11 changes: 11 additions & 0 deletions your_layout.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    ...
    <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" />
    ...