-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chromecast support #91
Comments
Okay so, I can't really contribute to any of this, my Flutter know-how is pretty basic, but I just wanted to express my excitement about this feature. |
Oh I've done something to work with Fuchsia (it`s early working) I'll make some tests if work I can PR it or push on someone's package supports to linux |
@allansrc wow that would be amazing! |
@guyluz11 thank you I tried your branch and it works as I can list the devices and can connec tto them and can send messages to them. Maybe I misunderstand something with how chromecast works, but can I send for example a podcast or a radio station to it? I just changed the very narrow bottom player (when musicpod is very narrow) to this, and it works as described above: import 'package:cast/device.dart';
import 'package:cast/discovery_service.dart';
import 'package:cast/session.dart';
import 'package:cast/session_manager.dart';
import 'package:flutter/material.dart';
import '../../player.dart';
import 'bottom_player_image.dart';
import 'bottom_player_title_artist.dart';
import 'play_button.dart';
class VeryNarrowBottomPlayer extends StatelessWidget {
const VeryNarrowBottomPlayer({
super.key,
required this.setFullScreen,
required this.bottomPlayerImage,
required this.titleAndArtist,
required this.active,
required this.isOnline,
required this.track,
});
final void Function(bool? p1) setFullScreen;
final BottomPlayerImage bottomPlayerImage;
final BottomPlayerTitleArtist titleAndArtist;
final bool active;
final bool isOnline;
final PlayerTrack track;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () => setFullScreen(true),
child: SizedBox(
height: kBottomPlayerHeight,
child: Column(
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 8),
child: bottomPlayerImage,
),
const SizedBox(
width: 20,
),
Expanded(
child: titleAndArtist,
),
Padding(
padding: const EdgeInsets.only(right: 20),
child: PlayButton(active: active),
),
Padding(
padding: const EdgeInsets.only(right: 20),
child: IconButton(
onPressed: () => showDialog(
context: context,
builder: (context) => const CastTestDialog(),
),
icon: const Icon(Icons.cast),
),
),
],
),
),
track,
],
),
),
);
}
}
class CastTestDialogContent extends StatelessWidget {
const CastTestDialogContent({super.key});
@override
Widget build(BuildContext context) {
return FutureBuilder<List<CastDevice>>(
future: CastDiscoveryService().search(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Center(
child: Text(
'Error: ${snapshot.error.toString()}',
),
);
} else if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator(),
);
}
if (snapshot.data!.isEmpty) {
return const Column(
children: [
Center(
child: Text(
'No Chromecast founded',
),
),
],
);
}
return Column(
children: snapshot.data!.map((device) {
return ListTile(
title: Text(device.name),
onTap: () => _connect(context, device),
);
}).toList(),
);
},
);
}
Future<void> _connect(BuildContext context, CastDevice object) async {
final session = await CastSessionManager().startSession(object);
session.stateStream.listen((state) {
if (state == CastSessionState.connected) {
_sendMessage(session);
}
});
session.messageStream.listen((message) {
print('receive message: $message');
});
session.sendMessage(CastSession.kNamespaceReceiver, {
'type': 'LAUNCH',
'appId': 'YouTube', // set the appId of your app here
});
}
void _sendMessage(CastSession session) {
session.sendMessage('urn:x-cast:namespace-of-the-app', {
'type': 'sample',
});
}
}
class CastTestDialog extends StatelessWidget {
const CastTestDialog({super.key});
@override
Widget build(BuildContext context) {
return const AlertDialog(
content: CastTestDialogContent(),
contentPadding: EdgeInsets.only(top: 20, bottom: 20),
);
}
} |
I didn't manage to open YouTube links.
Maybe I will work on it in the future. |
Hi 👋😊 I don't want to open it inside YouTube Only stream the audio and or video (video podcasts) to a Chromecast device |
Didn't check streaming but it should be a small change to already existing request |
Alright! |
I have a 3rd gen chromecast, it pretty much only supports H264 video and a very narrow range of audio codecs. You would need to transcode the media files for casting them. |
@CosmicRaptor would be super awesome if we could get this rolling for radio streams and podcasts, not for local audio |
@Feichtmeier I've never done anything related to Chromecast before unfortunately, I can't promise that I can do it |
If any change is needed in my fork feel free to open a pr |
Sure, I'll check it out. Unfortunately my parents have the Chromecast, I can only realistically work on this when I'm visiting them some time in December. |
Great Here is the link to my fork You can work on the example folder
|
https://pub.dev/packages/dart_chromecast/example
The text was updated successfully, but these errors were encountered: