From c84d3d9b72bdd93f84f837ceb54511d0cca5d1b4 Mon Sep 17 00:00:00 2001 From: suconghou <1126045770@qq.com> Date: Sun, 7 Aug 2022 14:43:47 +0800 Subject: [PATCH] update dlna --- android/build.gradle | 2 +- lib/ui/widgets/DlnaDeviceList.dart | 32 +++++++++++------------------ lib/ui/widgets/DlnaDialog.dart | 16 +++++++-------- lib/ui/widgets/DlnaStreamItems.dart | 2 +- lib/utils/videoInfo.dart | 13 +++++++----- pubspec.lock | 22 ++++++++++---------- pubspec.yaml | 2 +- 7 files changed, 42 insertions(+), 47 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index aaf27cc..9ec62d7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.6.21' repositories { // google() mavenCentral() diff --git a/lib/ui/widgets/DlnaDeviceList.dart b/lib/ui/widgets/DlnaDeviceList.dart index 0ad1bbb..b72e529 100644 --- a/lib/ui/widgets/DlnaDeviceList.dart +++ b/lib/ui/widgets/DlnaDeviceList.dart @@ -7,7 +7,7 @@ import 'package:dlna_dart/dlna.dart'; import './DlnaDialog.dart'; import '../utils/toast.dart'; -Map cacheDeviceList = {}; +Map cacheDeviceList = {}; class DlnaDeviceList extends StatefulWidget { final String? videoId; @@ -20,47 +20,40 @@ class DlnaDeviceList extends StatefulWidget { } class _DlnaDeviceListState extends State { - late search searcher; - late final manager m; - Timer timer = Timer(const Duration(seconds: 1), () {}); - Map deviceList = {}; + late DLNAManager searcher; + late final DeviceManager m; + Map deviceList = {}; _DlnaDeviceListState(); @override initState() { super.initState(); - searcher = search(); + searcher = DLNAManager(); init(); } init() async { m = await searcher.start(); - timer.cancel(); - callback(timer) { - m.deviceList.forEach((key, value) { + m.devices.stream.listen((dlist) { + dlist.forEach((key, value) { cacheDeviceList[key] = value; }); setState(() { deviceList = cacheDeviceList; }); - } - - timer = Timer.periodic(const Duration(seconds: 5), callback); - callback(null); + }); + await _pullToRefresh(); } @override void dispose() { - timer.cancel(); searcher.stop(); super.dispose(); } @override Widget build(BuildContext context) { - return deviceList.isEmpty - ? const Center(child: CircularProgressIndicator()) - : RefreshIndicator(onRefresh: _pullToRefresh, child: _body()); + return RefreshIndicator(onRefresh: _pullToRefresh, child: _body()); } Future _pullToRefresh() async { @@ -74,8 +67,7 @@ class _DlnaDeviceListState extends State { Widget _body() { if (deviceList.isEmpty) { - return const SizedBox( - height: 200, + return const Center( child: CircularProgressIndicator(), ); } @@ -89,7 +81,7 @@ class _DlnaDeviceListState extends State { ); } - Widget buildItem(String uri, device device) { + Widget buildItem(String uri, DLNADevice device) { final title = device.info.friendlyName; final subtitle = '$uri\r\n${device.info.deviceType}'; final s = subtitle.toLowerCase(); diff --git a/lib/ui/widgets/DlnaDialog.dart b/lib/ui/widgets/DlnaDialog.dart index 3312112..4199a84 100644 --- a/lib/ui/widgets/DlnaDialog.dart +++ b/lib/ui/widgets/DlnaDialog.dart @@ -10,7 +10,7 @@ import 'package:flutter_app/ui/utils/toast.dart'; import './DlnaStreamItems.dart'; class DlnaDialog extends StatefulWidget { - final device dev; + final DLNADevice dev; final String? videoId; const DlnaDialog(this.dev, {Key? key, this.videoId}) : super(key: key); @@ -21,7 +21,7 @@ class DlnaDialog extends StatefulWidget { } class _DlnaDialogState extends State { - positionParser? position; + PositionParser? position; TextEditingController videoUrl = TextEditingController(); Timer timer = Timer(const Duration(seconds: 1), () {}); @@ -30,7 +30,7 @@ class _DlnaDialogState extends State { super.initState(); callback(_) async { final text = await widget.dev.position(); - final p = positionParser(text); + final p = PositionParser(text); setState(() { position = p; }); @@ -155,7 +155,7 @@ class _DlnaDialogState extends State { Navigator.pop(context); Timer(const Duration(seconds: 2), () async { final text = await widget.dev.position(); - position = positionParser(text); + position = PositionParser(text); }); }, ); @@ -237,7 +237,7 @@ class _DlnaDialogState extends State { onPressed: () async { try { final curr = await widget.dev.position(); - final p = positionParser(curr); + final p = PositionParser(curr); setState(() { position = p; }); @@ -254,7 +254,7 @@ class _DlnaDialogState extends State { onPressed: () async { try { final curr = await widget.dev.position(); - final p = positionParser(curr); + final p = PositionParser(curr); setState(() { position = p; }); @@ -272,7 +272,7 @@ class _DlnaDialogState extends State { onPressed: () async { try { final curr = await widget.dev.position(); - final p = positionParser(curr); + final p = PositionParser(curr); setState(() { position = p; }); @@ -289,7 +289,7 @@ class _DlnaDialogState extends State { onPressed: () async { try { final curr = await widget.dev.position(); - final p = positionParser(curr); + final p = PositionParser(curr); setState(() { position = p; }); diff --git a/lib/ui/widgets/DlnaStreamItems.dart b/lib/ui/widgets/DlnaStreamItems.dart index 5dc6514..6a687bd 100644 --- a/lib/ui/widgets/DlnaStreamItems.dart +++ b/lib/ui/widgets/DlnaStreamItems.dart @@ -6,7 +6,7 @@ import 'package:dlna_dart/dlna.dart'; import 'package:flutter_app/ui/utils/toast.dart'; class DlnaStreamItems extends StatelessWidget { - final device dev; + final DLNADevice dev; final String videoId; const DlnaStreamItems(this.dev, this.videoId, {Key? key}) : super(key: key); diff --git a/lib/utils/videoInfo.dart b/lib/utils/videoInfo.dart index 147051c..282fed8 100644 --- a/lib/utils/videoInfo.dart +++ b/lib/utils/videoInfo.dart @@ -110,8 +110,11 @@ String viewCount(dynamic item) { if (n < 1) { return ""; } - if (n > 10000) { - return "${(n / 1000).round()}万观看"; + if (n > 1e8) { + return "${(n / 1e8).toStringAsFixed(2)}亿观看"; + } + if (n > 1e4) { + return "${(n / 1e4).toStringAsFixed(1)}万观看"; } return "$n观看"; } @@ -123,7 +126,7 @@ String pubAt(dynamic item) { final t = DateTime.parse(v["publishedAt"]); n = t.millisecondsSinceEpoch; } - final d = (DateTime.now().millisecondsSinceEpoch - n) / 1000; + final d = (DateTime.now().millisecondsSinceEpoch - n) / 1e3; const f = [ [31536000, '年'], [2592000, '个月'], @@ -196,8 +199,8 @@ String getSubscriberCount(dynamic item) { if (n < 1) { return ""; } - if (n > 10000) { - return "${(n / 1000).round()}万订阅者"; + if (n > 1e4) { + return "${(n / 1e4).toStringAsFixed(1)}万订阅者"; } return "$n订阅者"; } diff --git a/pubspec.lock b/pubspec.lock index 6977e79..a98292c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -77,7 +77,7 @@ packages: name: dlna_dart url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.5" + version: "0.0.6" fake_async: dependency: transitive description: @@ -91,7 +91,7 @@ packages: name: ffi url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.0.1" file: dependency: transitive description: @@ -183,21 +183,21 @@ packages: name: path_provider url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.10" + version: "2.0.11" path_provider_android: dependency: transitive description: name: path_provider_android url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.14" + version: "2.0.17" path_provider_ios: dependency: transitive description: name: path_provider_ios url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.9" + version: "2.0.11" path_provider_linux: dependency: transitive description: @@ -225,7 +225,7 @@ packages: name: path_provider_windows url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0" + version: "2.1.1" petitparser: dependency: transitive description: @@ -377,35 +377,35 @@ packages: name: video_player url: "https://pub.flutter-io.cn" source: hosted - version: "2.4.2" + version: "2.4.5" video_player_android: dependency: transitive description: name: video_player_android url: "https://pub.flutter-io.cn" source: hosted - version: "2.3.5" + version: "2.3.8" video_player_avfoundation: dependency: transitive description: name: video_player_avfoundation url: "https://pub.flutter-io.cn" source: hosted - version: "2.3.4" + version: "2.3.5" video_player_platform_interface: dependency: transitive description: name: video_player_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "5.1.2" + version: "5.1.3" video_player_web: dependency: transitive description: name: video_player_web url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.10" + version: "2.0.12" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 098241a..3e29de4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,7 +32,7 @@ dependencies: u2flutter_player: path: /Users/admin/data/git/flutter/u2flutter_player - dlna_dart: '>=0.0.5' + dlna_dart: '>=0.0.6' mediaindex_dart: '>=0.0.2' shared_preferences: '>=2.0.15' path_provider: '>=2.0.10'