Just_audio: Casting support

Created on 18 Oct 2020  路  18Comments  路  Source: ryanheise/just_audio

Is your feature request related to a problem? Please describe.
Not related to a problem

Describe the solution you'd like
Google/Chrome Cast support.
Function which can be called in Dart to retrieve all available devices to cast to, and 2 other functions to connect (and disconnect) on the remote devices.

Describe alternatives you've considered
None

Additional context
I am assuming that ExoPlayer would handle most of it: https://developers.google.com/cast/docs/android_sender/exoplayer

Thank you.

1 backlog enhancement

Most helpful comment

It's a good idea.

Note for later: This may also be possible on iOS via AirPlay.

All 18 comments

It's a good idea.

Note for later: This may also be possible on iOS via AirPlay.

Any newer thoughts on cast support? AirPlay already works automatically in iOS when playing media with your plugin - its kind of built in. I would love cast support for Android (iOS is likely never going to have a bunch of folks asking for it). With casting to a Chromecast or Google Cast, there's a fair amount of development and I would be willing to test/support this effort if you decide to go this route. Thanks for your hard work on this and Audio Service!

There is a discussion and some code over on #248 . Doing it right will require some planning on the Android side, particularly since it may require collaboration with the audio_service plugin.

My priority at the moment however is getting the next release of audio_service out, then releasing #311 , then working on #97 , #147 , #329 and somewhat related #307 , which in turn depend on #334 .

While I'm focused on those things, the discussion on casting can continue. I think it would help for anyone who wants to contribute in some way to start analysing the requirements of casting on the Android side and work out a draft design spec for how we will modify just_audio and audio_service to achieve this goal.

Thanks for the replay and detailed roadmap. I may work on null safety and take a look at 248 in order to add any insights that I may have. I have implemented audio-only casting in my current app which I'm presently re-writing in Flutter - hence my request.

Thanks @franklink , your insights would definitely be helpful.

Is Airplay on iOS working? I am not able to play get the audio playing on the remote airplay target.

Is Airplay on iOS working? I am not able to play get the audio playing on the remote airplay target.

Yes, I just tested in my app running Audio_Service 0.17.0-nullsafety.0 and Just_Audio 0.7.1 and AirPlay displays targets and moves playback to target once selected. Pause/play works both in the iOS media center and when going through Just_Audio. I am using a Yamaha receiver as my target.

I'm currently working on a pure dart casting library called audio_cast which may be a better fit in @ryanheise's existing audio ecosystem from a long-term point of view.

The plugin will support Chromecast via dart_chromecast, Airplay via multicast_dns, and DLNA via upnp. I am currently working on getting Chromecast support ready while DLNA is already implemented and working.

Similar to the federated plugin architecture everyone interested in contributing can write his own CastAdapter.

If you are, comment on this issue and we can find a task for you to do.

Tasks that can be done:

  • [ ] Add documentation
  • [ ] Migrate mp3_info to nullsafety (simple!)
  • [ ] Migrate upnp to nullsafety
  • [ ] Migrate dart_chromecast to nullsafety
  • [ ] Add support for Airplay (through AirplayCastAdapter)
  • [ ] Add Chromecast support @peterscodee

What do you think about the proposal?

Is Airplay on iOS working? I am not able to play get the audio playing on the remote airplay target.

Yes, I just tested in my app running Audio_Service 0.17.0-nullsafety.0 and Just_Audio 0.7.1 and AirPlay displays targets and moves playback to target once selected. Pause/play works both in the iOS media center and when going through Just_Audio. I am using a Yamaha receiver as my target.

Interesting, I am trying to Airplay to a AppleTV 4K, and playback seems to start from the phones perspective, but no sound is played from the tv and the play button on the phone becomes disabled.

I'm currently working on a pure dart casting library called audio_cast which may be a better fit in @ryanheise's existing audio ecosystem from a long-term point of view.

Awesome... This would definitely be the dream solution if it can be done as a separate plugin that slots into the ecosystem. On Android, how do you envisage handling an app's transition between a local player (e.g. just_audio) and the cast player? Do we remove the audio_service notification and replace it with the cast notification, or do we try to keep the audio_service notification and implement logic within the app to switch handling of the play/pause/etc callbacks to route to the cast player instead of the local player?

I'm currently working on a pure dart casting library called audio_cast which may be a better fit in @ryanheise's existing audio ecosystem from a long-term point of view.

I am very interested in the Chromecast part. How would that fit in the just_audio/audio_service ecosystem? I am very curious.

I tried to use flutter_video_cast together with audio_service and just_audio, but it allows to play only one song.

I'm currently working on a pure dart casting library called audio_cast which may be a better fit in @ryanheise's existing audio ecosystem from a long-term point of view.

Awesome... This would definitely be the dream solution if it can be done as a separate plugin that slots into the ecosystem. On Android, how do you envisage handling an app's transition between a local player (e.g. just_audio) and the cast player? Do we remove the audio_service notification and replace it with the cast notification, or do we try to keep the audio_service notification and implement logic within the app to switch handling of the play/pause/etc callbacks to route to the cast player instead of the local player?

I would keep the notification by implementing a casting API within just_audio and map callbacks to audio_cast similar to how audio_session is embedded while also being available as a standalone package.
What is your preference?

Not quite sure I understand the mechanics of this, since you didn't mention how audio_service fits in (this is where the notification is handled for on-device playback). But if we use the audio_service notification for on-device playback, to keep that notification going when switching to casting would seem to imply using the audio_service callbacks to control the cast player. Is that what you had in mind?

I'm currently working on a pure dart casting library called audio_cast which may be a better fit in @ryanheise's existing audio ecosystem from a long-term point of view.

I am very interested in the Chromecast part. How would that fit in the just_audio/audio_service ecosystem? I am very curious.

I tried to use flutter_video_cast together with audio_service and just_audio, but it allows to play only one song.

I have just added support for Chromecast devices.

As dart_chromecast currently does not pass static analysis which would result in an [UNIDENTIFIED] release on pub.dev, the next version will probably be delayed but you can use the version on git.

Not quite sure I understand the mechanics of this, since you didn't mention how audio_service fits in (this is where the notification is handled for on-device playback). But if we use the audio_service notification for on-device playback, to keep that notification going when switching to casting would seem to imply using the audio_service callbacks to control the cast player. Is that what you had in mind?

Not quite sure if I understood your question but audio_service callbacks should definitely control the cast player while casting.

That sounds really promising, I had the impression from the discussion over at #248 that managing this transition between local and cast players might be a bit more complicated, but it's great to hear that your solution can be plugged in like this.

That sounds really promising, I had the impression from the discussion over at #248 that managing this transition between local and cast players might be a bit more complicated, but it's great to hear that your solution can be plugged in like this.

We need to make sure that the package reaches some sort of a stable milestone and is tested on various different platforms as just_audio is a flutter favorite and used by a lot of developers.

I have just added support for Chromecast devices.

As dart_chromecast currently does not pass static analysis which would result in an [UNIDENTIFIED] release on pub.dev, the next version will probably be delayed but you can use the version on git.

Oh nice. I have been experimenting with the code from this example. The problem I encountered was passing the CastSender object (which is created when connecting) to the audio_service entrypoint (which is a top level function). I will continue on Monday.

I had a look at your code and it looks like you can play only one song at a time, but I think extending to a playlist would be easy using:

_castSender.loadPlaylist(List<CastMedia> media, {bool append = false, bool forceNext = false})

I can try your package, if it make my code easier in my project, and the contribute to it if you like.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sigjak picture sigjak  路  12Comments

cnttechio picture cnttechio  路  13Comments

ryanheise picture ryanheise  路  7Comments

llucax picture llucax  路  9Comments

suragch picture suragch  路  9Comments