Skip to content

Commit

Permalink
update dlna
Browse files Browse the repository at this point in the history
  • Loading branch information
suconghou committed Aug 7, 2022
1 parent abca6b1 commit c84d3d9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 47 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.6.21'
repositories {
// google()
mavenCentral()
Expand Down
32 changes: 12 additions & 20 deletions lib/ui/widgets/DlnaDeviceList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:dlna_dart/dlna.dart';
import './DlnaDialog.dart';
import '../utils/toast.dart';

Map<String, device> cacheDeviceList = {};
Map<String, DLNADevice> cacheDeviceList = {};

class DlnaDeviceList extends StatefulWidget {
final String? videoId;
Expand All @@ -20,47 +20,40 @@ class DlnaDeviceList extends StatefulWidget {
}

class _DlnaDeviceListState extends State<DlnaDeviceList> {
late search searcher;
late final manager m;
Timer timer = Timer(const Duration(seconds: 1), () {});
Map<String, device> deviceList = {};
late DLNAManager searcher;
late final DeviceManager m;
Map<String, DLNADevice> 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 {
Expand All @@ -74,8 +67,7 @@ class _DlnaDeviceListState extends State<DlnaDeviceList> {

Widget _body() {
if (deviceList.isEmpty) {
return const SizedBox(
height: 200,
return const Center(
child: CircularProgressIndicator(),
);
}
Expand All @@ -89,7 +81,7 @@ class _DlnaDeviceListState extends State<DlnaDeviceList> {
);
}

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();
Expand Down
16 changes: 8 additions & 8 deletions lib/ui/widgets/DlnaDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -21,7 +21,7 @@ class DlnaDialog extends StatefulWidget {
}

class _DlnaDialogState extends State<DlnaDialog> {
positionParser? position;
PositionParser? position;
TextEditingController videoUrl = TextEditingController();
Timer timer = Timer(const Duration(seconds: 1), () {});

Expand All @@ -30,7 +30,7 @@ class _DlnaDialogState extends State<DlnaDialog> {
super.initState();
callback(_) async {
final text = await widget.dev.position();
final p = positionParser(text);
final p = PositionParser(text);
setState(() {
position = p;
});
Expand Down Expand Up @@ -155,7 +155,7 @@ class _DlnaDialogState extends State<DlnaDialog> {
Navigator.pop(context);
Timer(const Duration(seconds: 2), () async {
final text = await widget.dev.position();
position = positionParser(text);
position = PositionParser(text);
});
},
);
Expand Down Expand Up @@ -237,7 +237,7 @@ class _DlnaDialogState extends State<DlnaDialog> {
onPressed: () async {
try {
final curr = await widget.dev.position();
final p = positionParser(curr);
final p = PositionParser(curr);
setState(() {
position = p;
});
Expand All @@ -254,7 +254,7 @@ class _DlnaDialogState extends State<DlnaDialog> {
onPressed: () async {
try {
final curr = await widget.dev.position();
final p = positionParser(curr);
final p = PositionParser(curr);
setState(() {
position = p;
});
Expand All @@ -272,7 +272,7 @@ class _DlnaDialogState extends State<DlnaDialog> {
onPressed: () async {
try {
final curr = await widget.dev.position();
final p = positionParser(curr);
final p = PositionParser(curr);
setState(() {
position = p;
});
Expand All @@ -289,7 +289,7 @@ class _DlnaDialogState extends State<DlnaDialog> {
onPressed: () async {
try {
final curr = await widget.dev.position();
final p = positionParser(curr);
final p = PositionParser(curr);
setState(() {
position = p;
});
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/widgets/DlnaStreamItems.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 8 additions & 5 deletions lib/utils/videoInfo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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观看";
}
Expand All @@ -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, '个月'],
Expand Down Expand Up @@ -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订阅者";
}
Expand Down
22 changes: 11 additions & 11 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit c84d3d9

Please sign in to comment.