Skip to content

Commit

Permalink
tmp: 一些没改完的内容
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Sep 28, 2024
1 parent 99f613a commit fc69e96
Show file tree
Hide file tree
Showing 16 changed files with 855 additions and 790 deletions.
26 changes: 13 additions & 13 deletions android/app/src/main/kotlin/com/orz12/PiliPalaX/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package com.orz12.PiliPalaX

import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
//import io.flutter.plugin.common.MethodChannel
import com.ryanheise.audioservice.AudioServiceActivity
import android.os.Build
import android.os.Bundle
import android.view.WindowManager.LayoutParams

class MainActivity : AudioServiceActivity() {
private lateinit var methodChannel: MethodChannel
// private lateinit var methodChannel: MethodChannel

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
methodChannel = MethodChannel(flutterEngine!!.getDartExecutor()!!.getBinaryMessenger(), CHANNEL)
}
// override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
// super.configureFlutterEngine(flutterEngine)
// methodChannel = MethodChannel(flutterEngine!!.getDartExecutor()!!.getBinaryMessenger(), CHANNEL)
// }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -24,12 +24,12 @@ class MainActivity : AudioServiceActivity() {
}
}

override fun onUserLeaveHint() {
super.onUserLeaveHint()
methodChannel.invokeMethod("onUserLeaveHint", null)
}
// override fun onUserLeaveHint() {
// super.onUserLeaveHint()
// methodChannel.invokeMethod("onUserLeaveHint", null)
// }

companion object {
private const val CHANNEL = "onUserLeaveHint"
}
// companion object {
// private const val CHANNEL = "onUserLeaveHint"
// }
}
4 changes: 2 additions & 2 deletions lib/pages/bangumi/introduction/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class BangumiIntroController extends GetxController {
int currentIndex =
episodes.indexWhere((e) => e.cid == videoDetailCtr.cid.value);
int prevIndex = currentIndex - 1;
PlayRepeat platRepeat = videoDetailCtr.plPlayerController.playRepeat;
PlayRepeat platRepeat = videoDetailCtr.plPlayerController!.playRepeat;
if (prevIndex < 0) {
if (platRepeat == PlayRepeat.listCycle) {
prevIndex = episodes.length - 1;
Expand All @@ -349,7 +349,7 @@ class BangumiIntroController extends GetxController {
late List episodes;
VideoDetailController videoDetailCtr =
Get.find<VideoDetailController>(tag: Get.arguments['heroTag']);
PlayRepeat platRepeat = videoDetailCtr.plPlayerController.playRepeat;
PlayRepeat platRepeat = videoDetailCtr.plPlayerController!.playRepeat;

if (bangumiDetail.value.episodes != null) {
episodes = bangumiDetail.value.episodes!;
Expand Down
5 changes: 2 additions & 3 deletions lib/pages/danmaku/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ class _PlDanmakuState extends State<PlDanmaku> {

// 播放器状态监听
void playerListener(PlayerStatus? status) {
if (status == PlayerStatus.paused) {
_controller?.pause();
}
if (status == PlayerStatus.playing) {
_controller?.onResume();
} else {
_controller?.pause();
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/pages/live_room/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {

@override
void dispose() {
floating?.dispose();
// floating?.dispose();
plPlayerController!.dispose();
super.dispose();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/live_room/widgets/bottom_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class _BottomControlState extends State<BottomControl> {
canUsePiP = false;
}
if (canUsePiP) {
await widget.floating!.enable(const EnableManual());
await widget.floating!.enable(const ImmediatePiP());
} else {}
},
icon: const Icon(
Expand Down
92 changes: 66 additions & 26 deletions lib/pages/video/detail/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class VideoDetailController extends GetxController
ReplyItemModel? firstFloor;
final scaffoldKey = GlobalKey<ScaffoldState>();
RxString bgCover = ''.obs;
PlPlayerController plPlayerController = PlPlayerController.getInstance();
PlPlayerController? plPlayerController;

late VideoItem firstVideo;
late AudioItem firstAudio;
Expand All @@ -84,7 +84,7 @@ class VideoDetailController extends GetxController
var userInfo;
late bool isFirstTime = true;
Floating? floating;
late PreferredSizeWidget headerControl;
PreferredSizeWidget? headerControl;

// late bool enableCDN;
late int? cacheVideoQa;
Expand All @@ -95,7 +95,7 @@ class VideoDetailController extends GetxController
PersistentBottomSheetController? replyReplyBottomSheetCtr;

@override
void onInit() {
void onInit() async {
super.onInit();
final Map argMap = Get.arguments;
userInfo = userInfoCache.get('userInfoCache');
Expand All @@ -108,7 +108,9 @@ class VideoDetailController extends GetxController
}
}
if (keys.contains('pic')) {
videoItem['pic'] = argMap['pic'];
if (argMap['pic'] != null && argMap['pic'] != '') {
videoItem['pic'] = argMap['pic'];
}
}
}
bool defaultShowComment =
Expand All @@ -117,7 +119,28 @@ class VideoDetailController extends GetxController
length: 2, vsync: this, initialIndex: defaultShowComment ? 1 : 0);
autoPlay.value =
setting.get(SettingBoxKey.autoPlayEnable, defaultValue: true);
if (autoPlay.value) isShowCover.value = false;
if (autoPlay.value) {
isShowCover.value = false;
plPlayerController = PlPlayerController.getInstance();
headerControl = HeaderControl(
controller: plPlayerController,
videoDetailCtr: this,
floating: floating,
heroTag: heroTag,
);
}
if (videoItem['pic']?.isEmpty != false) {
VideoHttp.videoIntro(bvid: bvid).then(
(value) {
if (value['status']) {
videoItem['pic'] = value['data'].pic;
isShowCover.refresh();
} else {
SmartDialog.showToast("视频封面获取失败:${value['msg']}");
}
},
);
}
enableHA.value = setting.get(SettingBoxKey.enableHA, defaultValue: true);
hwdec.value = setting.get(SettingBoxKey.hardwareDecoding,
defaultValue: Platform.isAndroid ? 'auto-safe' : 'auto');
Expand All @@ -131,12 +154,6 @@ class VideoDetailController extends GetxController
if (Platform.isAndroid) {
floating = Floating();
}
headerControl = HeaderControl(
controller: plPlayerController,
videoDetailCtr: this,
floating: floating,
heroTag: heroTag,
);
// CDN优化
// enableCDN = setting.get(SettingBoxKey.enableCDN, defaultValue: true);

Expand All @@ -150,7 +167,12 @@ class VideoDetailController extends GetxController
defaultValue: VideoDecodeFormats.values[1].code);
cacheAudioQa = setting.get(SettingBoxKey.defaultAudioQa,
defaultValue: AudioQuality.hiRes.code);
oid.value = IdUtils.bv2av(Get.parameters['bvid']!);
if (Get.parameters['bvid'] != null && Get.parameters['bvid']!.isNotEmpty) {
oid.value = IdUtils.bv2av(Get.parameters['bvid']!);
} else {
SmartDialog.showToast('视频信息获取失败,可能为充电视频等特殊情况');
oid.value = 0;
}
}

showReplyReplyPanel() {
Expand Down Expand Up @@ -178,11 +200,12 @@ class VideoDetailController extends GetxController
/// 更新画质、音质
/// TODO 继续进度播放
updatePlayer() {
if (plPlayerController == null) return;
isShowCover.value = false;
defaultST = plPlayerController.position.value;
plPlayerController.removeListeners();
plPlayerController.isBuffering.value = false;
plPlayerController.buffered.value = Duration.zero;
defaultST = plPlayerController!.position.value;
plPlayerController!.removeListeners();
plPlayerController!.isBuffering.value = false;
plPlayerController!.buffered.value = Duration.zero;

/// 根据currentVideoQa和currentDecodeFormats 重新设置videoUrl
List<VideoItem> videoList =
Expand Down Expand Up @@ -266,11 +289,15 @@ class VideoDetailController extends GetxController
/// 设置/恢复 屏幕亮度
if (brightness != null) {
ScreenBrightness().setScreenBrightness(brightness!);
} else if (setting.get(SettingBoxKey.enableAutoBrightness,
defaultValue: false) as bool) {
ScreenBrightness().resetScreenBrightness();
}
await plPlayerController.setDataSource(
plPlayerController ??= PlPlayerController.getInstance();
headerControl ??= HeaderControl(
controller: plPlayerController,
videoDetailCtr: this,
floating: floating,
heroTag: heroTag,
);
await plPlayerController!.setDataSource(
DataSource(
videoSource: video ?? videoUrl,
audioSource: audio ?? audioUrl,
Expand Down Expand Up @@ -301,7 +328,7 @@ class VideoDetailController extends GetxController
);

/// 开启自动全屏时,在player初始化完成后立即传入headerControl
plPlayerController.headerControl = headerControl;
plPlayerController!.headerControl = headerControl;
}

// 视频链接
Expand All @@ -310,9 +337,10 @@ class VideoDetailController extends GetxController
if (result['status']) {
data = result['data'];
if (data.acceptDesc!.isNotEmpty && data.acceptDesc!.contains('试看')) {
SmartDialog.showToast(
'该视频为专属视频,仅提供试看',
SmartDialog.showNotify(
msg: '该视频为专属视频,仅提供试看',
displayTime: const Duration(seconds: 3),
notifyType: NotifyType.warning,
);
}
if (data.dash == null && data.durl != null) {
Expand All @@ -334,7 +362,11 @@ class VideoDetailController extends GetxController
return result;
}
if (data.dash == null) {
SmartDialog.showToast('视频资源不存在');
SmartDialog.showNotify(
msg: '视频资源不存在',
displayTime: const Duration(seconds: 3),
notifyType: NotifyType.error,
);
isShowCover.value = false;
return result;
}
Expand Down Expand Up @@ -438,12 +470,20 @@ class VideoDetailController extends GetxController
} else {
if (result['code'] == -404) {
isShowCover.value = false;
SmartDialog.showToast('视频不存在或已被删除');
SmartDialog.showNotify(
msg: '视频不存在或已被删除',
displayTime: const Duration(seconds: 3),
notifyType: NotifyType.error,
);
}
if (result['code'] == 87008) {
SmartDialog.showToast("当前视频可能是专属视频,可能需包月充电观看(${result['msg']})");
} else {
SmartDialog.showToast("错误(${result['code']}):${result['msg']}");
SmartDialog.showNotify(
msg: '错误(${result['code']}):${result['msg']}',
displayTime: const Duration(seconds: 3),
notifyType: NotifyType.warning,
);
}
}
return result;
Expand Down
19 changes: 12 additions & 7 deletions lib/pages/video/detail/introduction/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ class VideoIntroController extends GetxController {
int prevIndex = currentIndex - 1;
final VideoDetailController videoDetailCtr =
Get.find<VideoDetailController>(tag: heroTag);
final PlayRepeat platRepeat = videoDetailCtr.plPlayerController.playRepeat;
final PlayRepeat platRepeat = videoDetailCtr.plPlayerController!.playRepeat;

// 列表循环
if (prevIndex < 0) {
Expand Down Expand Up @@ -558,12 +558,17 @@ class VideoIntroController extends GetxController {
final List<Part> pages = videoDetail.value.pages!;
episodes.addAll(pages);
}
final VideoDetailController videoDetailCtr =
Get.find<VideoDetailController>(tag: heroTag);
final PlayRepeat platRepeat = videoDetailCtr.plPlayerController.playRepeat;
late VideoDetailController videoDetailCtr;
PlayRepeat playRepeat = PlayRepeat.listCycle;
try {
videoDetailCtr = Get.find<VideoDetailController>(tag: heroTag);
playRepeat = videoDetailCtr.plPlayerController!.playRepeat;
} catch (_) {
return false;
}

if (episodes.isEmpty) {
if (platRepeat == PlayRepeat.autoPlayRelated) {
if (playRepeat == PlayRepeat.autoPlayRelated) {
return playRelated();
}
return false;
Expand All @@ -575,9 +580,9 @@ class VideoIntroController extends GetxController {

// 列表循环
if (nextIndex >= episodes.length) {
if (platRepeat == PlayRepeat.listCycle) {
if (playRepeat == PlayRepeat.listCycle) {
nextIndex = 0;
} else if (platRepeat == PlayRepeat.autoPlayRelated) {
} else if (playRepeat == PlayRepeat.autoPlayRelated) {
return playRelated();
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/video/detail/reply/widgets/reply_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ InlineSpan buildContent(
SmartDialog.showToast('跳转至:$matchStr');
Get.find<VideoDetailController>(
tag: Get.arguments['heroTag'])
.plPlayerController
.plPlayerController!
.seekTo(Duration(seconds: Utils.duration(matchStr)),
type: 'slider');
} catch (e) {
Expand Down
Loading

0 comments on commit fc69e96

Please sign in to comment.