terrabythia / dart_chromecast

Dart package to play videos to a chromecast device
MIT License
62 stars 66 forks source link

Cant find any device in network #52

Open renanmgs opened 2 years ago

renanmgs commented 2 years ago

The funcion find_chromecast.find_chromecasts() is not able to return any device in network, and trow an error : "Dart Socket ERROR: ../../third_party/dart/runtime/bin/socket_android.cc:147: reusePort not supported for Android."

The error can be fixed adding rawDatagramSocketFactory to MDnsClient() but it stills not returning any device.

My code:

 @override
  void initState() {
    findCastingDevices();

    super.initState();
  }

Future<void> findCastingDevices() async {
    // search!
    print('Looking for ChromeCast devices...');
    devices = (await find_chromecast.find_chromecasts()).cast<find_chromecast.CastDevice>();
    if (devices.length == 0) {
      print('No devices found!');
      Future.delayed(Duration(seconds: 45), () {
        findCastingDevices();
      });
      return;
    }

    print("Found ${devices.length} devices:");
    for (int i = 0; i < devices.length; i++) {
      int index = i + 1;
      find_chromecast.CastDevice device = devices[i];
      print("$index: ${device.name}");
    }
    setState(() {});
  }
renanmgs commented 2 years ago

@terrabythia