0

My application has Videos, Audios and Photos. I'm successfully able to cast all three of them. However when I cast an image, the minicontrollerfragment, Notification and ExpandedControllerActivity shows video controls. When I click play/pause button it just keeps spinning round for photo.

Is there a way where I can disable it for images? I looked up everywhere but for some reason I was not able to find a single example of Photo.

Any help would be appreciated. Thank you.

Here is the code for CastOptionsProvider.

 @Override
public CastOptions getCastOptions(Context context) {

    NotificationOptions notificationOptions = new NotificationOptions.Builder()
            .setTargetActivityClassName(ExpandedControlsActivity.class.getName())
            .setActions(Arrays.asList(MediaIntentReceiver.ACTION_REWIND,MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK, MediaIntentReceiver.ACTION_FORWARD, MediaIntentReceiver.ACTION_STOP_CASTING), new int[]{1,2,3})
            .build();
    CastMediaOptions mediaOptions = new CastMediaOptions.Builder()
            .setNotificationOptions(notificationOptions)
            .setExpandedControllerActivityClassName(ExpandedControlsActivity.class.getName())
            .build();

    CastOptions castOptions = new CastOptions.Builder()
            .setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
            .setCastMediaOptions(mediaOptions)
            .build();
    return castOptions;
}

This is how I cast an image:

MediaMetadata photoMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_PHOTO);
photoMetadata.putString(MediaMetadata.KEY_TITLE, "Casting to " + mCastSession.getCastDevice().getFriendlyName());
photoMetadata.addImage(new WebImage(Uri.parse(photoItem.getImageUrl())));

MediaInfo mediaInfo = new MediaInfo.Builder(photoItem.getImageUrl())
        .setContentType("image/jpeg")
        .setMetadata(photoMetadata)
        .setStreamDuration(0)
        .setStreamType(MediaInfo.STREAM_TYPE_NONE)
        .build();
MediaLoadOptions mediaLoadOptions = new MediaLoadOptions.Builder()
        .setAutoplay(true)
        .setPlayPosition(0)
        .build();

RemoteMediaClient remoteMediaClient = mCastSession.getRemoteMediaClient();
remoteMediaClient.load(mediaInfo, mediaLoadOptions);
Sagar
  • 416
  • 7
  • 23
  • 1
    You can file an issue: https://issuetracker.google.com/issues?q=componentid:190205%20status:open&s=modified_time:desc – Leon Nicholls Jun 06 '18 at 19:34

1 Answers1

0

You can use Default Media Receiver (CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID) to give it a try as a default receiver, otherwise you need to create your own.

Inside your CastOptionProvider, create a CastOptions like below

new CastOptions.Builder()
            .setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
            .setCastMediaOptions(mediaOptions)
            .build();
DayDayHappy
  • 1,679
  • 1
  • 15
  • 26