Control third-party Cast session from Android?
I want to observe and control a Chromecast session that was started by another app.
When connecting using MediaRouter
, however, I cannot join an ongoing session without disrupting it. As soon as I select a route, my app replaces the previous one.
How can I monitor a Chromecast session using the Android SDK (and be able to play, pause, see progress, etc), without replacing the receiver app that is currently playing?

add a comment |
I want to observe and control a Chromecast session that was started by another app.
When connecting using MediaRouter
, however, I cannot join an ongoing session without disrupting it. As soon as I select a route, my app replaces the previous one.
How can I monitor a Chromecast session using the Android SDK (and be able to play, pause, see progress, etc), without replacing the receiver app that is currently playing?

Can you share your (best) implementation? Maybe it is something as simple as a wrong parameter.
– leonardkraemer
Jan 9 at 5:04
1
I solved the problem by using the lower-level (deprecated) Cast API v2, which has much finer access and does not kill the currently playing application when it connects. This is the APICastContext
uses under the hood. I'll answer my own question with the code when it's ready
– slezica
Jan 9 at 17:48
add a comment |
I want to observe and control a Chromecast session that was started by another app.
When connecting using MediaRouter
, however, I cannot join an ongoing session without disrupting it. As soon as I select a route, my app replaces the previous one.
How can I monitor a Chromecast session using the Android SDK (and be able to play, pause, see progress, etc), without replacing the receiver app that is currently playing?

I want to observe and control a Chromecast session that was started by another app.
When connecting using MediaRouter
, however, I cannot join an ongoing session without disrupting it. As soon as I select a route, my app replaces the previous one.
How can I monitor a Chromecast session using the Android SDK (and be able to play, pause, see progress, etc), without replacing the receiver app that is currently playing?


asked Dec 31 '18 at 5:39
slezicaslezica
44.6k1675136
44.6k1675136
Can you share your (best) implementation? Maybe it is something as simple as a wrong parameter.
– leonardkraemer
Jan 9 at 5:04
1
I solved the problem by using the lower-level (deprecated) Cast API v2, which has much finer access and does not kill the currently playing application when it connects. This is the APICastContext
uses under the hood. I'll answer my own question with the code when it's ready
– slezica
Jan 9 at 17:48
add a comment |
Can you share your (best) implementation? Maybe it is something as simple as a wrong parameter.
– leonardkraemer
Jan 9 at 5:04
1
I solved the problem by using the lower-level (deprecated) Cast API v2, which has much finer access and does not kill the currently playing application when it connects. This is the APICastContext
uses under the hood. I'll answer my own question with the code when it's ready
– slezica
Jan 9 at 17:48
Can you share your (best) implementation? Maybe it is something as simple as a wrong parameter.
– leonardkraemer
Jan 9 at 5:04
Can you share your (best) implementation? Maybe it is something as simple as a wrong parameter.
– leonardkraemer
Jan 9 at 5:04
1
1
I solved the problem by using the lower-level (deprecated) Cast API v2, which has much finer access and does not kill the currently playing application when it connects. This is the API
CastContext
uses under the hood. I'll answer my own question with the code when it's ready– slezica
Jan 9 at 17:48
I solved the problem by using the lower-level (deprecated) Cast API v2, which has much finer access and does not kill the currently playing application when it connects. This is the API
CastContext
uses under the hood. I'll answer my own question with the code when it's ready– slezica
Jan 9 at 17:48
add a comment |
1 Answer
1
active
oldest
votes
First Option:
You can use a RemotePlaybackClient
Controlling a remote playback route
When you select a remote playback route your app acts as a remote
control. The device at the other end of the route handles all content
data retrieval, decoding, and playback functions. The controls in your
app's UI communicate with the receiver device using a
RemotePlaybackClient object.
Javadoc:
RemotePlaybackClient
A helper class for playing media on remote routes using the remote
playback protocol defined by MediaControlIntent.
The client maintains session state and offers a simplified interface
for issuing remote playback media control intents to a single route.
You can create it with RemotePlaybackClient(Context context, MediaRouter.RouteInfo route)
You can check if the MediaRouter.Route
supports remote requests by calling route.supportsControlCategory
Second Option:
If your app does not support this you can try managing through the CastSession. This way you app will communicate with the other app through the chromeecast. With CastSession.getRemoteMediaClient()
you get a RemoteMediaClient
.
Tried that. At least with a direct approach, it throwsjava.lang.UnsupportedOperationException: The route does not support session management.
. Does it require additional initialization? Can I use it on a Route I have not "connected" to, when I don't control the receiver app?
– slezica
Jan 2 at 18:37
You can check if theMediaRouter
supports remote requests by calling supportscontrolcategory
– leonardkraemer
Jan 2 at 18:54
Update: theRemotePlaybackClient
, created with the Chromecast route, does not support session management, remote playback or anything else. I cannot call any of its methods. I can connect perfectly using theCastSession
API, but that stops the current receiver app
– slezica
Jan 5 at 1:33
Are you sure that it is not the android os closing the other app and therefore stopping playback? Afaik connecting withCastSession.getRemoteMediaClient()
does not stop playback.
– leonardkraemer
Jan 5 at 2:06
CastSession
automatically launches a new receiver application when connected to the Route (eg by selecting a route from the standard cast button dialog). This stops playback unless the application is the same.
– slezica
Jan 5 at 16:43
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53983977%2fcontrol-third-party-cast-session-from-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First Option:
You can use a RemotePlaybackClient
Controlling a remote playback route
When you select a remote playback route your app acts as a remote
control. The device at the other end of the route handles all content
data retrieval, decoding, and playback functions. The controls in your
app's UI communicate with the receiver device using a
RemotePlaybackClient object.
Javadoc:
RemotePlaybackClient
A helper class for playing media on remote routes using the remote
playback protocol defined by MediaControlIntent.
The client maintains session state and offers a simplified interface
for issuing remote playback media control intents to a single route.
You can create it with RemotePlaybackClient(Context context, MediaRouter.RouteInfo route)
You can check if the MediaRouter.Route
supports remote requests by calling route.supportsControlCategory
Second Option:
If your app does not support this you can try managing through the CastSession. This way you app will communicate with the other app through the chromeecast. With CastSession.getRemoteMediaClient()
you get a RemoteMediaClient
.
Tried that. At least with a direct approach, it throwsjava.lang.UnsupportedOperationException: The route does not support session management.
. Does it require additional initialization? Can I use it on a Route I have not "connected" to, when I don't control the receiver app?
– slezica
Jan 2 at 18:37
You can check if theMediaRouter
supports remote requests by calling supportscontrolcategory
– leonardkraemer
Jan 2 at 18:54
Update: theRemotePlaybackClient
, created with the Chromecast route, does not support session management, remote playback or anything else. I cannot call any of its methods. I can connect perfectly using theCastSession
API, but that stops the current receiver app
– slezica
Jan 5 at 1:33
Are you sure that it is not the android os closing the other app and therefore stopping playback? Afaik connecting withCastSession.getRemoteMediaClient()
does not stop playback.
– leonardkraemer
Jan 5 at 2:06
CastSession
automatically launches a new receiver application when connected to the Route (eg by selecting a route from the standard cast button dialog). This stops playback unless the application is the same.
– slezica
Jan 5 at 16:43
|
show 4 more comments
First Option:
You can use a RemotePlaybackClient
Controlling a remote playback route
When you select a remote playback route your app acts as a remote
control. The device at the other end of the route handles all content
data retrieval, decoding, and playback functions. The controls in your
app's UI communicate with the receiver device using a
RemotePlaybackClient object.
Javadoc:
RemotePlaybackClient
A helper class for playing media on remote routes using the remote
playback protocol defined by MediaControlIntent.
The client maintains session state and offers a simplified interface
for issuing remote playback media control intents to a single route.
You can create it with RemotePlaybackClient(Context context, MediaRouter.RouteInfo route)
You can check if the MediaRouter.Route
supports remote requests by calling route.supportsControlCategory
Second Option:
If your app does not support this you can try managing through the CastSession. This way you app will communicate with the other app through the chromeecast. With CastSession.getRemoteMediaClient()
you get a RemoteMediaClient
.
Tried that. At least with a direct approach, it throwsjava.lang.UnsupportedOperationException: The route does not support session management.
. Does it require additional initialization? Can I use it on a Route I have not "connected" to, when I don't control the receiver app?
– slezica
Jan 2 at 18:37
You can check if theMediaRouter
supports remote requests by calling supportscontrolcategory
– leonardkraemer
Jan 2 at 18:54
Update: theRemotePlaybackClient
, created with the Chromecast route, does not support session management, remote playback or anything else. I cannot call any of its methods. I can connect perfectly using theCastSession
API, but that stops the current receiver app
– slezica
Jan 5 at 1:33
Are you sure that it is not the android os closing the other app and therefore stopping playback? Afaik connecting withCastSession.getRemoteMediaClient()
does not stop playback.
– leonardkraemer
Jan 5 at 2:06
CastSession
automatically launches a new receiver application when connected to the Route (eg by selecting a route from the standard cast button dialog). This stops playback unless the application is the same.
– slezica
Jan 5 at 16:43
|
show 4 more comments
First Option:
You can use a RemotePlaybackClient
Controlling a remote playback route
When you select a remote playback route your app acts as a remote
control. The device at the other end of the route handles all content
data retrieval, decoding, and playback functions. The controls in your
app's UI communicate with the receiver device using a
RemotePlaybackClient object.
Javadoc:
RemotePlaybackClient
A helper class for playing media on remote routes using the remote
playback protocol defined by MediaControlIntent.
The client maintains session state and offers a simplified interface
for issuing remote playback media control intents to a single route.
You can create it with RemotePlaybackClient(Context context, MediaRouter.RouteInfo route)
You can check if the MediaRouter.Route
supports remote requests by calling route.supportsControlCategory
Second Option:
If your app does not support this you can try managing through the CastSession. This way you app will communicate with the other app through the chromeecast. With CastSession.getRemoteMediaClient()
you get a RemoteMediaClient
.
First Option:
You can use a RemotePlaybackClient
Controlling a remote playback route
When you select a remote playback route your app acts as a remote
control. The device at the other end of the route handles all content
data retrieval, decoding, and playback functions. The controls in your
app's UI communicate with the receiver device using a
RemotePlaybackClient object.
Javadoc:
RemotePlaybackClient
A helper class for playing media on remote routes using the remote
playback protocol defined by MediaControlIntent.
The client maintains session state and offers a simplified interface
for issuing remote playback media control intents to a single route.
You can create it with RemotePlaybackClient(Context context, MediaRouter.RouteInfo route)
You can check if the MediaRouter.Route
supports remote requests by calling route.supportsControlCategory
Second Option:
If your app does not support this you can try managing through the CastSession. This way you app will communicate with the other app through the chromeecast. With CastSession.getRemoteMediaClient()
you get a RemoteMediaClient
.
edited Jan 5 at 2:04
answered Jan 2 at 17:56
leonardkraemerleonardkraemer
3,51211634
3,51211634
Tried that. At least with a direct approach, it throwsjava.lang.UnsupportedOperationException: The route does not support session management.
. Does it require additional initialization? Can I use it on a Route I have not "connected" to, when I don't control the receiver app?
– slezica
Jan 2 at 18:37
You can check if theMediaRouter
supports remote requests by calling supportscontrolcategory
– leonardkraemer
Jan 2 at 18:54
Update: theRemotePlaybackClient
, created with the Chromecast route, does not support session management, remote playback or anything else. I cannot call any of its methods. I can connect perfectly using theCastSession
API, but that stops the current receiver app
– slezica
Jan 5 at 1:33
Are you sure that it is not the android os closing the other app and therefore stopping playback? Afaik connecting withCastSession.getRemoteMediaClient()
does not stop playback.
– leonardkraemer
Jan 5 at 2:06
CastSession
automatically launches a new receiver application when connected to the Route (eg by selecting a route from the standard cast button dialog). This stops playback unless the application is the same.
– slezica
Jan 5 at 16:43
|
show 4 more comments
Tried that. At least with a direct approach, it throwsjava.lang.UnsupportedOperationException: The route does not support session management.
. Does it require additional initialization? Can I use it on a Route I have not "connected" to, when I don't control the receiver app?
– slezica
Jan 2 at 18:37
You can check if theMediaRouter
supports remote requests by calling supportscontrolcategory
– leonardkraemer
Jan 2 at 18:54
Update: theRemotePlaybackClient
, created with the Chromecast route, does not support session management, remote playback or anything else. I cannot call any of its methods. I can connect perfectly using theCastSession
API, but that stops the current receiver app
– slezica
Jan 5 at 1:33
Are you sure that it is not the android os closing the other app and therefore stopping playback? Afaik connecting withCastSession.getRemoteMediaClient()
does not stop playback.
– leonardkraemer
Jan 5 at 2:06
CastSession
automatically launches a new receiver application when connected to the Route (eg by selecting a route from the standard cast button dialog). This stops playback unless the application is the same.
– slezica
Jan 5 at 16:43
Tried that. At least with a direct approach, it throws
java.lang.UnsupportedOperationException: The route does not support session management.
. Does it require additional initialization? Can I use it on a Route I have not "connected" to, when I don't control the receiver app?– slezica
Jan 2 at 18:37
Tried that. At least with a direct approach, it throws
java.lang.UnsupportedOperationException: The route does not support session management.
. Does it require additional initialization? Can I use it on a Route I have not "connected" to, when I don't control the receiver app?– slezica
Jan 2 at 18:37
You can check if the
MediaRouter
supports remote requests by calling supportscontrolcategory– leonardkraemer
Jan 2 at 18:54
You can check if the
MediaRouter
supports remote requests by calling supportscontrolcategory– leonardkraemer
Jan 2 at 18:54
Update: the
RemotePlaybackClient
, created with the Chromecast route, does not support session management, remote playback or anything else. I cannot call any of its methods. I can connect perfectly using the CastSession
API, but that stops the current receiver app– slezica
Jan 5 at 1:33
Update: the
RemotePlaybackClient
, created with the Chromecast route, does not support session management, remote playback or anything else. I cannot call any of its methods. I can connect perfectly using the CastSession
API, but that stops the current receiver app– slezica
Jan 5 at 1:33
Are you sure that it is not the android os closing the other app and therefore stopping playback? Afaik connecting with
CastSession.getRemoteMediaClient()
does not stop playback.– leonardkraemer
Jan 5 at 2:06
Are you sure that it is not the android os closing the other app and therefore stopping playback? Afaik connecting with
CastSession.getRemoteMediaClient()
does not stop playback.– leonardkraemer
Jan 5 at 2:06
CastSession
automatically launches a new receiver application when connected to the Route (eg by selecting a route from the standard cast button dialog). This stops playback unless the application is the same.– slezica
Jan 5 at 16:43
CastSession
automatically launches a new receiver application when connected to the Route (eg by selecting a route from the standard cast button dialog). This stops playback unless the application is the same.– slezica
Jan 5 at 16:43
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53983977%2fcontrol-third-party-cast-session-from-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you share your (best) implementation? Maybe it is something as simple as a wrong parameter.
– leonardkraemer
Jan 9 at 5:04
1
I solved the problem by using the lower-level (deprecated) Cast API v2, which has much finer access and does not kill the currently playing application when it connects. This is the API
CastContext
uses under the hood. I'll answer my own question with the code when it's ready– slezica
Jan 9 at 17:48