lcote
lcote

Reputation: 101

AndroidChromecastSDK (Xamarin Bindings) : Getting the RemoteMediaPlayer.MediaStatus always return null

I'm developping a custom sender application for chromecast in C# using Xamarin. At this point, I can send MediaInfo to the receiver app and play a song correctly on my TV. The problem I have is when I try to stop the RemoteMediaPlayer.

Calling Stop() on the player returns a Java.Lang.IllegalStateException : No current media session exception. This is weird since I can hear the music playing, so there must be an active media session...

Also, I tried setting the OnStatusUpdatedListener (AndroidMediaPlayer inherits from RemoteMediaPlayer) like this

mediaPlayer = new AndroidMediaPlayer();
mediaPlayer.SetOnStatusUpdatedListener(new AndroidMediaPlayerOnStatusUpdated(this, mediaPlayer));

with a custom implementation of the Interface

internal class AndroidMediaPlayerOnStatusUpdated: Java.Lang.Object, RemoteMediaPlayer.IOnStatusUpdatedListener {
    private readonly AndroidChromecastController controller;
    private readonly RemoteMediaPlayer mediaPlayer;
    public AndroidMediaPlayerOnStatusUpdated(AndroidChromecastController aController, RemoteMediaPlayer aMediaPlayer) {
        controller = aController;
        mediaPlayer = aMediaPlayer;
    }

    public void OnStatusUpdated()
    {
        var status = mediaPlayer.MediaStatus;
        switch (status.PlayerState)
        {
            case MediaStatus.PlayerStateBuffering:
                break;
            case MediaStatus.PlayerStateIdle:
                break;
            case MediaStatus.PlayerStatePaused:
                break;
            case MediaStatus.PlayerStatePlaying:
                break;
            case MediaStatus.PlayerStateUnknown:
                break;
        }
    }
}

The OnStatusUpdated method never gets called however, even if i call the RequestStatus method on the RemoteMediaPlayer.

Is there something I'm doing plain wrong or is something not working in Xamarin's bindings of GooglePlayServices?

Thanks in advance and I can provide clarification if needed!

Upvotes: 0

Views: 342

Answers (1)

lcote
lcote

Reputation: 101

For anyone who might come across this problem, be wary that you need to use this line :

CastClass.CastApi.SetMessageReceivedCallbacks(googleApiClient, mediaPlayer.Namespace, mediaPlayer);

where mediaPlayer is a RemoteMediaPlayer.

My problem was that I was using a custom implementation of the RemoteMediaPlayer and I overrided the Namespace get attribute to return a Namespace of my liking and that is okay with the documentation. See here :

https://developer.android.com/reference/com/google/android/gms/cast/Cast.CastApi.html#setMessageReceivedCallbacks(com.google.android.gms.common.api.GoogleApiClient, java.lang.String, com.google.android.gms.cast.Cast.MessageReceivedCallback)

(For some reason, there is a space (and I can't remove it as it would break the link) in the link and it's destroying the linking method for this website, but the link is correct if you copy and paste it... Sorry about that)

Even if my Namespace was of the format they want, it would not work. But it would not throw any exception.

Upvotes: 1

Related Questions