Martin Marconcini
Martin Marconcini

Reputation: 27226

Using the CastCompanionLibrary to cast audio only?

By taking a look at the samples, libraries, source code, etc. from Google Cast, I can say that the whole Cast SDK is relatively complicated and has little abstraction to the dev.

I assume that's why Google created the CastCompanionLibrary…

However, by reading the .pdf, source code and the sample, it's still not clear to me what the right approach to casting only audio is.

On the other side of the spectrum is the not-yet-Android-Studio updated "democastplayer".

I've converted this app to Android Studio and it works with my own App Id, but I still have two fundamental questions:

1) What is the difference between Cast SDK Mode and MediaRouter Mode? (Even looking at the source code, I have not yet been able to find the difference or advantage of one over the other, or more specifically, when to use each and why?)

2) If you already have a Service that does all you need (because you already have an app that streams music) using a standard MediaPlayer, you already buffer (async!) and play when the player is prepared, you also have a notification in the bar, in other words, you have a media player app… how would you approach adding Chromecast Support?

CastCompanionLibrary seems relatively bloated with unneeded features (a player Activity/fragment that I don't need because I already have one), notification support which I already have in my App… etc.

Should I just approach it in a way where there's a "second" player/service in my App that is exclusive to Chromecast and therefore takes care of all the Notification, RemoteMediaPlayer (as opposed to my regular MediaPlayer), etc.?

Will this player give me a callback when playback is finished? paused? (So I can update my UI, make my API calls, etc.)

I'm new to Google Cast, so apologies in advance if anything is easy to see, please point me to the right resources (I've read the samples and code, but haven't come across these simple answers). I am not interested in video at all.

My music comes from an API (I have to request a track and I will get a URL to the media -mp3 or similar-). I also have to know when the track has reached certain point. I haven't seen anything similar to the real MediaPlayer in the RemoteMediaPlayer, those callbacks seem incomplete to me.

What am I missing here? :)

Thanks.

Upvotes: 2

Views: 602

Answers (1)

Ali Naddaf
Ali Naddaf

Reputation: 19034

You have different choices:

  • You can use the CastCompanionLibrary and subclass DataCastManager to add the pieces that you want. That (and the next option below) would handle connectivity issues, etc.
  • You can use the CastCompanionLibrary and use VideoCastManager. If you don't need notifications, you don't have to use it; that is a feature that is not going to be there unless you enable it. I haven't used that class for music only but I can't see any major issue. The advantage is that it gives you a set of call backs to inform you of the state of the music playback and a host of APIs to do other things easily.
  • You can write your own code from scratch; you can register for media status updates callback and be informed when music stops, buffers, .... It is not a difficult task and looking at the samples would tell you what you need to do; practically there is very little difference, as far as the SDK is concerned, between dealing with videos or music.

Upvotes: 1

Related Questions