dlna_dart
simple dlna client
Getting Started
import 'dart:async';
import 'package:dlna_dart/dlna.dart';
main(List<String> args) async {
final searcher = DLNAManager();
final m = await searcher.start();
m.devices.stream.listen((deviceList) {
deviceList.forEach((key, value) async {
print(key);
if (value.info.friendlyName.contains('Wireless')) return;
print(value.info.friendlyName);
print(value.activeTime);
print('\r\n');
// final text = await value.position();
// final r = await value.seekByCurrent(text, 10);
// print(r);
});
});
// close the server,the closed server can be start by call searcher.start()
Timer(Duration(seconds: 30), () {
searcher.stop();
print('server closed');
});
// if you new DLNAManager() many times , you must use start(reusePort:true)
}
Android
Android drops multicast packets for apps by default. Without a
WifiManager.MulticastLock the search still works for devices that answer
M-SEARCH (the reply is unicast), but ssdp:alive / ssdp:byebye NOTIFY
packets are dropped, so the device list only refreshes by polling and
offline devices linger until they time out. Some vendor ROMs are stricter
and drop multicast entirely.
This package is pure Dart and cannot acquire the lock for you. In your app:
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
val wifi = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
val lock = wifi.createMulticastLock("dlna_dart").apply { setReferenceCounted(true) }
lock.acquire()
// ... discover ...
lock.release()
python version
https://github.com/suconghou/dlna-python
app example