What Payload to send to the Chromecast Default Media Receiver via Cast.CastApi.sendMessage

StackOverflow https://stackoverflow.com/questions/23416648

  •  13-07-2023
  •  | 
  •  

문제

I have been trying to build a little test application that sends data from an android app (sender) to my chromecast. I am using the Default Media Receiver to avoid paying for registration while I learn.

All the code is implemented in an service, the receiver is found and ready but i don't know how to format the payload to actually get the Media Receiver to do anything (display images for example)

Here is a bit of code (if more is needed I gladly post it). The onConnected() method is called and runs without errors, the receiver is connected and ready, showing the chromecast symbol but the picture of which I send the URL is not shown.

private class ConnectionCallbacks implements GoogleApiClient.ConnectionCallbacks
{

    @Override
    public void onConnected(Bundle bundle)
    {

        Log.d(TAG, "on connected for callback");
 Cast.CastApi.launchApplication(mApiClient,
                CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID, false)
                .setResultCallback(new ResultCallback<Cast.ApplicationConnectionResult>()
                {
                    @Override
                    public void onResult(Cast.ApplicationConnectionResult result)
                    {
                        Log.d(TAG, "OnResultCallback... ");
                        Status status = result.getStatus();
                        Log.d(TAG, "ApplicationConnectionResultCallback.onResult: statusCode" + status.getStatusCode());
                        if (status.isSuccess())
                        {
                            mApplicationStarted=true;
                            ApplicationMetadata applicationMetadata = result.getApplicationMetadata();
                            mSessionId = result.getSessionId();
                            String applicationStatus = result.getApplicationStatus();
                            boolean wasLaunched = result.getWasLaunched();
                            Log.d(TAG, mSessionId+" "+applicationStatus);
                            try
                            {
                                Cast.CastApi.sendMessage(mApiClient, "urn:x-cast:com.google.cast.media",
                                        "http://www.randomwebsite.com/images/head.jpg")
                                        .setResultCallback(new ResultCallback<Status>()
                                        {
                                            @Override
                                            public void onResult(Status result)
                                            {
                                                if (!result.isSuccess())
                                                {
                                                    Log.e(TAG, "Sending message failed");
                                                }
                                            }
                                        });
                            }
                            catch(Exception e)
                            {
                                Log.e(TAG, "Sending message to chromecast failed... hard.");
                            }
                        }
                    }
                });
    }

    @Override
    public void onConnectionSuspended(int i)
    {
        Log.d(TAG, "on connection suspended for callback");
    }
}

This and most of the code is similar to the https://github.com/googlecast/CastHelloText-android example from google.

My problem, I think is the line Cast.CastApi.sendMessage(mApiClient, "urn:x-cast:com.google.cast.media", "http://www.randomwebsite.com/images/head.jpg") especially the third parameter which i suspect just isn't formatted the way the Default Media Receiver expects data. However I could not find any working examples on this.

So, how does one get a working example using the Default Media Receiver to run?

도움이 되었습니까?

해결책

If you want to send you own messages (non-media), you should create a custom receiver with your own namespace. The Default Receiver/Styled Receiver only understands media namespace and to use that namespace, do not use sendMessage; use RemoteMediaPlayer to send common actions like play/pause/stop/seek/... There are some samples on our GitHub repo.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top