Skip to content

Commit

Permalink
Merge pull request #304 from xiaoyaocz/dev
Browse files Browse the repository at this point in the history
Release 1.4.8
  • Loading branch information
xiaoyaocz authored Feb 5, 2024
2 parents bc3dccf + 220fda5 commit cbdf0a1
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish_app_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Flutter action
uses: subosito/flutter-action@v2
with:
flutter-version: '3.16.5'
flutter-version: '3.16.x'
cache: true

#更新Flutter的packages
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_app_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Flutter action
uses: subosito/flutter-action@v2
with:
flutter-version: '3.16.5'
flutter-version: '3.16.x'
cache: true
#更新Flutter的packages
- name: Restore packages
Expand Down
6 changes: 3 additions & 3 deletions assets/app_version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "1.4.7",
"version_num": 10407,
"version_desc": "- 非横屏隐藏首页左侧分割线 #235\n- 优化设置页面的UI\n- 修复抖音Web链接跳转错误 #248\n- 增加不再提示登录选项 #219\n- 增加数据网络下清晰度设置 #237\n- 增加进入后台自动暂停选项 #240\n- 进入后台时不添加弹幕 #230\n- 修复抖音直播加载问题 #275",
"version": "1.4.8",
"version_num": 10408,
"version_desc": "- 修复抖音内容加载失败问题 #285\n- iOS放开后台播放设置\n- 修复音量拖动调节时卡顿问题 #92 (#294 @abcghy)\n- 弹幕支持使用正则屏蔽 #283 (#295 @abcghy)\n- 定时关闭建议记忆上次设定的时长 #278 (#296 @abcghy)",
"prerelease":false,
"download_url": "https://github.com/xiaoyaocz/dart_simple_live/releases"
}
20 changes: 20 additions & 0 deletions simple_live_app/lib/app/controller/app_settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class AppSettingsController extends GetxController {
autoExitDuration.value = LocalStorageService.instance
.getValue(LocalStorageService.kAutoExitDuration, 60);

roomAutoExitDuration.value = LocalStorageService.instance
.getValue(LocalStorageService.kRoomAutoExitDuration, 60);

playerCompatMode.value = LocalStorageService.instance
.getValue(LocalStorageService.kPlayerCompatMode, false);

Expand Down Expand Up @@ -92,6 +95,9 @@ class AppSettingsController extends GetxController {
bilibiliLoginTip.value = LocalStorageService.instance
.getValue(LocalStorageService.kBilibiliLoginTip, true);

playerBufferSize.value = LocalStorageService.instance
.getValue(LocalStorageService.kPlayerBufferSize, 32);

initSiteSort();
initHomeSort();
super.onInit();
Expand Down Expand Up @@ -277,13 +283,27 @@ class AppSettingsController extends GetxController {
.setValue(LocalStorageService.kAutoExitDuration, e);
}

var roomAutoExitDuration = 60.obs;
void setRoomAutoExitDuration(int e) {
roomAutoExitDuration.value = e;
LocalStorageService.instance
.setValue(LocalStorageService.kRoomAutoExitDuration, e);
}

var playerCompatMode = false.obs;
void setPlayerCompatMode(bool e) {
playerCompatMode.value = e;
LocalStorageService.instance
.setValue(LocalStorageService.kPlayerCompatMode, e);
}

var playerBufferSize = 32.obs;
void setPlayerBufferSize(int e) {
playerBufferSize.value = e;
LocalStorageService.instance
.setValue(LocalStorageService.kPlayerBufferSize, e);
}

var playerAutoPause = false.obs;
void setPlayerAutoPause(bool e) {
playerAutoPause.value = e;
Expand Down
28 changes: 28 additions & 0 deletions simple_live_app/lib/app/custom_throttle.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// 这个类的目的是简化 throttle 的操作,以便更好的理解代码
/// 主要作用:节流,如果在很短时间内都会调用同一个方法,除了第一个方法有用以外
/// 剩下的方法将会被舍弃,在 [eachDelayMilli] 时间后,才会允许下一次调用
/// 会保存一个方法,在最后还会调用一次,和普通的 throttle 不太一样
class DelayedThrottle {
bool isInvoking = false;
int eachDelayMilli;
Future Function()? storeFunc;

DelayedThrottle(this.eachDelayMilli);

void invoke(Future Function() longCostFunc) {
if (isInvoking) {
storeFunc = longCostFunc;
return;
}
storeFunc = null;
isInvoking = true;
longCostFunc().then((value) {
Future.delayed(Duration(milliseconds: eachDelayMilli), () {
isInvoking = false;
if (storeFunc != null) {
invoke(storeFunc!);
}
});
});
}
}
8 changes: 8 additions & 0 deletions simple_live_app/lib/app/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,12 @@ class Utils {
}
return null;
}

static bool isRegexFormat(String keyword) {
return keyword.startsWith('/') && keyword.endsWith('/') && keyword.length > 2;
}

static String removeRegexFormat(String keyword) {
return keyword.substring(1, keyword.length - 1);
}
}
20 changes: 18 additions & 2 deletions simple_live_app/lib/modules/live_room/live_room_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ class LiveRoomController extends PlayerController with WidgetsBindingObserver {
autoExitMinutes.value =
AppSettingsController.instance.autoExitDuration.value;
setAutoExit();
} else {
autoExitMinutes.value =
AppSettingsController.instance.roomAutoExitDuration.value;
}
}

Expand Down Expand Up @@ -198,8 +201,20 @@ class LiveRoomController extends PlayerController with WidgetsBindingObserver {

// 关键词屏蔽检查
for (var keyword in AppSettingsController.instance.shieldList) {
if (msg.message.contains(keyword)) {
Log.d("关键词:$keyword\n消息内容:${msg.message}");
Pattern? pattern;
if (Utils.isRegexFormat(keyword)) {
String removedSlash = Utils.removeRegexFormat(keyword);
try {
pattern = RegExp(removedSlash);
} catch (e) {
// should avoid this during add keyword
Log.d("关键词:$keyword 正则格式错误");
}
} else {
pattern = keyword;
}
if (pattern != null && msg.message.contains(pattern)) {
Log.d("关键词:$keyword\n已屏蔽消息内容:${msg.message}");
return;
}
}
Expand Down Expand Up @@ -805,6 +820,7 @@ class LiveRoomController extends PlayerController with WidgetsBindingObserver {
var duration =
Duration(hours: value.hour, minutes: value.minute);
autoExitMinutes.value = duration.inMinutes;
AppSettingsController.instance.setRoomAutoExitDuration(autoExitMinutes.value);
//setAutoExitDuration(duration.inMinutes);
setAutoExit();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:perfect_volume_control/perfect_volume_control.dart';
import 'package:screen_brightness/screen_brightness.dart';
import 'package:simple_live_app/app/controller/app_settings_controller.dart';
import 'package:simple_live_app/app/controller/base_controller.dart';
import 'package:simple_live_app/app/custom_throttle.dart';
import 'package:simple_live_app/app/log.dart';
import 'package:simple_live_app/app/utils.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
Expand All @@ -28,6 +29,9 @@ mixin PlayerMixin {
late final player = Player(
configuration: const PlayerConfiguration(
title: "Simple Live Player",
// bufferSize:
// // media-kit #549
// AppSettingsController.instance.playerBufferSize.value * 1024 * 1024,
),
);

Expand All @@ -42,6 +46,7 @@ mixin PlayerMixin {
: VideoControllerConfiguration(
enableHardwareAcceleration:
AppSettingsController.instance.hardwareDecode.value,
androidAttachSurfaceAfterVideoParameters: false,
),
);
}
Expand Down Expand Up @@ -375,6 +380,8 @@ mixin PlayerGestureControlMixin
var _currentBrightness = 1.0;
var verStartPosition = 0.0;

DelayedThrottle? throttle;

/// 竖向手势开始
void onVerticalDragStart(DragStartDetails details) async {
if (lockControlsState.value && fullScreenState.value) {
Expand All @@ -390,6 +397,8 @@ mixin PlayerGestureControlMixin
verStartPosition = dy;
leftVerticalDrag = details.globalPosition.dx < Get.width / 2;

throttle = DelayedThrottle(200);

verticalDragging = true;
showGestureTip.value = true;
_currentVolume = await PerfectVolumeControl.volume;
Expand All @@ -415,30 +424,43 @@ mixin PlayerGestureControlMixin
}
}

int lastVolume = -1; // it's ok to be -1

void setGestureVolume(double dy) {
double value = 0.0;
double seek;
if (dy > verStartPosition) {
value = ((dy - verStartPosition) / (Get.height * 0.5));

var seek = _currentVolume - value;
seek = _currentVolume - value;
if (seek < 0) {
seek = 0;
}
PerfectVolumeControl.setVolume(seek);
gestureTipText.value = "音量 ${(seek * 100).toInt()}%";
Log.logPrint(value);
} else {
value = ((dy - verStartPosition) / (Get.height * 0.5));
var seek = value.abs() + _currentVolume;
seek = value.abs() + _currentVolume;
if (seek > 1) {
seek = 1;
}
}
int volume = _convertVolume((seek * 100).round());
if (volume == lastVolume) {
return;
}
lastVolume = volume;
// update UI outside throttle to make it more fluent
gestureTipText.value = "音量 $volume%";
throttle?.invoke(() async => await _realSetVolume(volume));
}

PerfectVolumeControl.setVolume(seek);
// 0 to 100, 5 step each
int _convertVolume(int volume) {
return (volume / 5).round() * 5;
}

gestureTipText.value = "音量 ${(seek * 100).toInt()}%";
Log.logPrint(value);
}
Future<void> _realSetVolume(int volume) async {
Log.logPrint(volume);
return await PerfectVolumeControl.setVolume(volume / 100);
}

void setGestureBrightness(double dy) {
Expand Down Expand Up @@ -472,6 +494,7 @@ mixin PlayerGestureControlMixin
if (lockControlsState.value && fullScreenState.value) {
return;
}
throttle = null;
verticalDragging = false;
leftVerticalDrag = false;
showGestureTip.value = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DanmuShieldPage extends GetView<DanmuShieldController> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("弹幕关键词屏蔽"),
title: const Text("弹幕屏蔽"),
),
body: ListView(
padding: AppStyle.edgeInsetsA12,
Expand All @@ -20,7 +20,7 @@ class DanmuShieldPage extends GetView<DanmuShieldController> {
decoration: InputDecoration(
contentPadding: AppStyle.edgeInsetsH12,
border: const OutlineInputBorder(),
hintText: "请输入关键词",
hintText: "请输入关键词或正则表达式",
suffixIcon: TextButton.icon(
onPressed: controller.add,
icon: const Icon(Icons.add),
Expand All @@ -31,6 +31,11 @@ class DanmuShieldPage extends GetView<DanmuShieldController> {
controller.add();
},
),
AppStyle.vGap4,
Text(
'以"/"开头和结尾将视作正则表达式, 如"/\\d+/"表示屏蔽所有数字',
style: Get.textTheme.bodySmall,
),
AppStyle.vGap12,
Obx(
() => Text(
Expand Down
32 changes: 22 additions & 10 deletions simple_live_app/lib/modules/user/play_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PlaySettingsPage extends GetView<AppSettingsController> {
},
),
),
AppStyle.divider,
if (Platform.isAndroid) AppStyle.divider,
Obx(
() => Visibility(
visible: Platform.isAndroid,
Expand All @@ -56,17 +56,29 @@ class PlaySettingsPage extends GetView<AppSettingsController> {
),
),
),
// AppStyle.divider,
// Obx(
// () => SettingsNumber(
// title: "缓冲区大小",
// subtitle: "若播放卡顿可尝试调高此选项",
// value: controller.playerBufferSize.value,
// min: 32,
// max: 1024,
// step: 4,
// unit: "MB",
// onChanged: (e) {
// controller.setPlayerBufferSize(e);
// },
// ),
// ),
AppStyle.divider,
Obx(
() => Visibility(
visible: Platform.isAndroid,
child: SettingsSwitch(
title: "进入后台自动暂停",
value: controller.playerAutoPause.value,
onChanged: (e) {
controller.setPlayerAutoPause(e);
},
),
() => SettingsSwitch(
title: "进入后台自动暂停",
value: controller.playerAutoPause.value,
onChanged: (e) {
controller.setPlayerAutoPause(e);
},
),
),
AppStyle.divider,
Expand Down
7 changes: 7 additions & 0 deletions simple_live_app/lib/services/local_storage_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,19 @@ class LocalStorageService extends GetxService {
/// 定时关闭时间(分钟)
static const String kAutoExitDuration = "AutoExitDuration";

/// 房间内定时关闭时间(分钟)
/// 需要一个不同的 key,因为用户在房间内设置的倒计时和全局的可能不同。
static const String kRoomAutoExitDuration = "RoomAutoExitDuration";

/// 播放器兼容模式
static const String kPlayerCompatMode = "PlayerCompatMode";

/// 播放器后台自动暂停
static const String kPlayerAutoPause = "PlayerAutoPause";

/// 播放器缓冲区大小
static const String kPlayerBufferSize = "PlayerBufferSize";

/// 自动全屏
static const String kAutoFullScreen = "AutoFullScreen";

Expand Down
2 changes: 1 addition & 1 deletion simple_live_app/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: simple_live_app
version: 1.4.7+10407
version: 1.4.8+10408
publish_to: none
description: "Simple Live APP"
environment:
Expand Down
Loading

0 comments on commit cbdf0a1

Please sign in to comment.