just_audio icon indicating copy to clipboard operation
just_audio copied to clipboard

Casting support

Open Marekkon5 opened this issue 3 years ago • 42 comments

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.

Marekkon5 avatar Oct 18 '20 08:10 Marekkon5

It's a good idea.

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

ryanheise avatar Oct 24 '20 03:10 ryanheise

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!

franklink avatar Mar 15 '21 00:03 franklink

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.

ryanheise avatar Mar 15 '21 01:03 ryanheise

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.

franklink avatar Mar 16 '21 22:03 franklink

Thanks @franklink , your insights would definitely be helpful.

ryanheise avatar Mar 17 '21 04:03 ryanheise

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

esiqveland avatar Apr 07 '21 18:04 esiqveland

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.

franklink avatar Apr 07 '21 19:04 franklink

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?

dxvid-pts avatar Apr 07 '21 19:04 dxvid-pts

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.

esiqveland avatar Apr 07 '21 20:04 esiqveland

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?

ryanheise avatar Apr 08 '21 02:04 ryanheise

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.

mvolpato avatar Apr 08 '21 15:04 mvolpato

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?

dxvid-pts avatar Apr 10 '21 16:04 dxvid-pts

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?

ryanheise avatar Apr 10 '21 16:04 ryanheise

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.

dxvid-pts avatar Apr 10 '21 16:04 dxvid-pts

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.

dxvid-pts avatar Apr 10 '21 16:04 dxvid-pts

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.

ryanheise avatar Apr 10 '21 16:04 ryanheise

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.

dxvid-pts avatar Apr 10 '21 17:04 dxvid-pts

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.

mvolpato avatar Apr 10 '21 17:04 mvolpato

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?

This is exactly what i need. Care to share details and status?

bafplus avatar Jul 18 '21 16:07 bafplus

Please refer to YT music cast feature

derakula avatar Sep 12 '21 15:09 derakula

Hello. Any updates? How I help with implementing this feature? I use just_audio + audio_service in projects in my work, maybe you help with links to how I implement it?

alexey-nobody avatar Jan 11 '22 11:01 alexey-nobody

Also curious. Our current implementation combining audio_service & flutter_video_cast is feeling a bit rusty

markst avatar Feb 18 '22 12:02 markst

I think audio_cast has promise (this was shared by @peterscodee above), so I would encourage people to take a look at it, create issues for anything that doesn't work, and consider poking around in the code yourself to see in what way you might be able to contribute given that these are all open source projects and contributions would most likely be welcome.

ryanheise avatar Feb 18 '22 13:02 ryanheise

definitely prepared to contribute @ryanheise. thanks for response, will have a look

markst avatar Feb 18 '22 13:02 markst

This is exactly what i need. Care to share details and status?

I have stopped actively working on the project, but I will support every pull request coming from the community if someone wants to move the project forward.

dxvid-pts avatar Feb 18 '22 19:02 dxvid-pts

Looks like doing a null safety migration would be a good first step for someone to contribute.

https://dart.dev/null-safety/migration-guide

ryanheise avatar Feb 20 '22 15:02 ryanheise

Hi,

I am one of the maintainers of the audio_cast package. We have now null safety support and are trying to test and improve the code and make it more stable. AirPlay support will take a bit more time as I want to focus on the stability of this package and iOS devices can use AirPlay right out of the box.

daniel-naegele avatar Apr 12 '22 13:04 daniel-naegele

What good timing. I actually forked that project Sunday and found it was already null safe. I was, however, having trouble reliably getting notified about multiple devices on the network. Maybe that's something you are addressing?

Thanks

franklink avatar Apr 12 '22 14:04 franklink

Yeah I just pushed a fix for that particular issue. The upnp device discoverer was in fact only discovering the first device

daniel-naegele avatar Apr 12 '22 14:04 daniel-naegele

Not sure if either of these are relevant, but adding them here since I stumbled upon:

https://github.com/mschneider/flutter_google_cast_plugin

https://github.com/gianlucaparadise/flutter_cast_framework

markst avatar Apr 21 '22 21:04 markst

Not sure if either of these are relevant, but adding them here since I stumbled upon:

https://github.com/mschneider/flutter_google_cast_plugin

https://github.com/gianlucaparadise/flutter_cast_framework

I've looked into flutter_cast_framework. It is a much more mature solution but it conflicts with audio_service due to mismatching base Android activity. The thing about this project is it actually uses Google's cast framework which might be advantageous in the long run as more features are needed. I'm fairly motivated because I've rewritten my app in Flutter and the only thing I'm missing in Android is cast support.

franklink avatar Apr 27 '22 22:04 franklink

I've looked into flutter_cast_framework. It is a much more mature solution but it conflicts with audio_service due to mismatching base Android activity.

Can you provide more detail on what the mismatching base activity is? I think I have seen issues before where different flutter plugins can conflict possibly due to conflicting gradle dependencies.

ryanheise avatar Apr 28 '22 02:04 ryanheise

@ryanheise Apologies as I may have spoken too soon. I do have it running after some work and it seems to be working well, but this is in tandem to your library. I'm testing to see what works and what doesn't, but it will take a lot of mapping on your part to integrate this level of native UI interaction. I'm going to keep working on the tandem integration for my own purposes, but I feel like this library offers so much more robustness and out-of-the-box UI elements that it may worth the effort.

franklink avatar May 06 '22 00:05 franklink

Any developments here? Seems like @gianlucaparadise is putting some effort into https://github.com/gianlucaparadise/flutter_cast_framework

markst avatar Jul 25 '22 19:07 markst

flutter_cast_framework doesn't seem to have a licence yet which would need to be sorted out before anyone can contribute to it or before anyone can "use it", for that matter, (and it isn't published on pub.dev yet, so you'd need to get it from git). But if it is indeed the most feature complete, I should check it out and investigate the reported build conflict.

ryanheise avatar Jul 26 '22 07:07 ryanheise

About flutter_cast_framework:

  1. I will add the license soon. My bad, I forgot to do it. Spoiler: it will be Apache 2.0
  2. I did not publish the library yet because I wanted to finish to support all the features. Eventually it will be published, but if you already find flutter_cast_framework ready for your work, I can publish an alpha version. I may introduce breaking change in the future, though.

gianlucaparadise avatar Jul 27 '22 18:07 gianlucaparadise