fix: 图片提交4x,提示画质。iOS logo提交;
This commit is contained in:
1 parent
2f1ec27802
commit
9e10608245
85 files changed
+1027
-645
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:skywood/global/client/event_client.dart';
|
||||
import 'package:skywood/global/client/play_client.dart';
|
||||
import 'package:skywood/main/lib_file.dart';
|
||||
import 'package:skywood/pages/home/players/page/drama_esp_page.dart';
|
||||
@@ -15,6 +16,7 @@ class SkyPlayerView extends StatefulWidget {
|
||||
final SkywoodDetail? detailBean;
|
||||
final SkywoodDrama dramaBean;
|
||||
final int? currentEpisode;
|
||||
final ValueChanged<SkywoodEpisode>? onSelectedEpisode;
|
||||
|
||||
const SkyPlayerView({
|
||||
super.key,
|
||||
@@ -23,6 +25,7 @@ class SkyPlayerView extends StatefulWidget {
|
||||
this.detailBean,
|
||||
required this.dramaBean,
|
||||
this.currentEpisode,
|
||||
this.onSelectedEpisode,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -40,6 +43,8 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
Duration _totalDuration = Duration.zero;
|
||||
bool _isLiked = false;
|
||||
SkywoodEpisode? _currentEpisode;
|
||||
// 是否已经上报his
|
||||
bool _isReportedHis = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -47,14 +52,15 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
_initializePlayer();
|
||||
}
|
||||
|
||||
// @override
|
||||
// void didUpdateWidget(SkyPlayerView oldWidget) {
|
||||
// super.didUpdateWidget(oldWidget);
|
||||
// if (oldWidget.videoUrl != widget.videoUrl) {
|
||||
// _disposeController();
|
||||
// _initializePlayer();
|
||||
// }
|
||||
// }
|
||||
@override
|
||||
void didUpdateWidget(SkyPlayerView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.detailBean != widget.detailBean ||
|
||||
oldWidget.currentEpisode != widget.currentEpisode) {
|
||||
_disposeController();
|
||||
_initializePlayer();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initializePlayer() async {
|
||||
setState(() {
|
||||
@@ -66,18 +72,10 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
_isLiked = widget.dramaBean.isCollect ?? false;
|
||||
});
|
||||
|
||||
int _esp = widget.currentEpisode ?? 0;
|
||||
String videoUrl = '';
|
||||
if (widget.detailBean != null) {
|
||||
if (widget.detailBean!.episodeList.isNotEmpty) {
|
||||
videoUrl = widget.detailBean!.episodeList[_esp].videoUrl;
|
||||
_currentEpisode = widget.detailBean!.episodeList[_esp];
|
||||
}
|
||||
}
|
||||
_currentEpisode = _resolveCurrentEpisode();
|
||||
String videoUrl = _currentEpisode?.videoUrl ?? '';
|
||||
|
||||
final controller = VideoPlayerController.networkUrl(
|
||||
Uri.parse(videoUrl),
|
||||
);
|
||||
final controller = VideoPlayerController.networkUrl(Uri.parse(videoUrl));
|
||||
_controller = controller;
|
||||
_controllerCreated = true;
|
||||
controller.addListener(_handlePlayerValueChanged);
|
||||
@@ -104,6 +102,17 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
void _handlePlayerValueChanged() {
|
||||
if (!mounted || !_controllerCreated) return;
|
||||
_syncPlayerValue();
|
||||
|
||||
final videoController = _controller;
|
||||
final position = videoController.value.position;
|
||||
final duration = videoController.value.duration;
|
||||
if (_isPlaying && !_isReportedHis && position.inSeconds > 1) {
|
||||
_isReportedHis = true;
|
||||
EventClient.eventCreateHis(
|
||||
shortPlayId: _currentEpisode!.shortPlayId.toString(),
|
||||
videoId: _currentEpisode!.shortPlayVideoId.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _syncPlayerValue() {
|
||||
@@ -194,9 +203,7 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
Widget _buildLoadingView() {
|
||||
return Container(
|
||||
color: Colors.black,
|
||||
child: Center(
|
||||
child: HelpImg.asset(ConstImg.loading, width: 110),
|
||||
),
|
||||
child: Center(child: HelpImg.asset(ConstImg.loading, width: 110)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -223,17 +230,39 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
}
|
||||
}
|
||||
|
||||
SkywoodEpisode? _resolveCurrentEpisode() {
|
||||
final detail = widget.detailBean;
|
||||
if (detail == null || detail.episodeList.isEmpty) return null;
|
||||
|
||||
final int? episode =
|
||||
widget.currentEpisode ??
|
||||
detail.videoInfo?.episode ??
|
||||
detail.videoInfo?.currentEpisode ??
|
||||
detail.shortPlayInfo?.episode ??
|
||||
detail.shortPlayInfo?.currentEpisode;
|
||||
|
||||
if (episode != null && episode > 0) {
|
||||
for (final item in detail.episodeList) {
|
||||
if (item.episode == episode) return item;
|
||||
}
|
||||
}
|
||||
|
||||
return detail.episodeList.first;
|
||||
}
|
||||
|
||||
void _collectionDrama() {
|
||||
if (_currentEpisode == null) return;
|
||||
if (_isLiked) {
|
||||
PlayClient.cancelCollect(shortPlayId: _currentEpisode!.shortPlayId).then((value) {
|
||||
PlayClient.cancelCollect(shortPlayId: _currentEpisode!.shortPlayId).then((
|
||||
value,
|
||||
) {
|
||||
setState(() {
|
||||
_isLiked = value;
|
||||
});
|
||||
});
|
||||
} else {
|
||||
PlayClient.collect(
|
||||
shortPlayId: _currentEpisode!.shortPlayId,
|
||||
shortPlayId: _currentEpisode!.shortPlayId,
|
||||
videoId: _currentEpisode!.shortPlayVideoId,
|
||||
).then((value) {
|
||||
setState(() {
|
||||
@@ -257,8 +286,9 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
InkWell(
|
||||
onTap: () => _collectionDrama(),
|
||||
child: HelpImg.asset(
|
||||
_isLiked ? ConstImg.liked : ConstImg.unlike,
|
||||
width: 40, height: 40
|
||||
_isLiked ? ConstImg.liked : ConstImg.unlike,
|
||||
width: 40,
|
||||
height: 40,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
@@ -282,7 +312,7 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
color: Colors.white,
|
||||
),
|
||||
SkyText(
|
||||
text: ' / EP.${detail.episodeList.length}',
|
||||
text: ' / EP.$totalEpisode',
|
||||
fontSize: 13,
|
||||
color: Colors.white.withAlpha(126),
|
||||
),
|
||||
@@ -293,9 +323,6 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
),
|
||||
).addInkWell(
|
||||
onTap: () {
|
||||
// HelpNav.showBottom(
|
||||
// DramaEspPage(detail: detail, currentEpisode: currentEpisode),
|
||||
// );
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
@@ -307,12 +334,8 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
detail: detail,
|
||||
currentEpisode: currentEpisode,
|
||||
onSelectedEpisode: (episode) {
|
||||
|
||||
if (widget.detailBean != null) {
|
||||
if (widget.detailBean!.episodeList.isNotEmpty) {
|
||||
_currentEpisode = widget.detailBean!.episodeList[episode];
|
||||
}
|
||||
}
|
||||
Navigator.pop(context);
|
||||
widget.onSelectedEpisode?.call(episode);
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -361,9 +384,7 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
child: SliderTheme(
|
||||
data: SliderThemeData(
|
||||
trackHeight: 3, // ✅ 进度条高度 3
|
||||
thumbShape: _ImageThumbShape(
|
||||
imagePath: ConstImg.playTag
|
||||
),
|
||||
thumbShape: _ImageThumbShape(imagePath: ConstImg.playTag),
|
||||
overlayShape: const RoundSliderOverlayShape(overlayRadius: 3),
|
||||
activeTrackColor: Colors.white, // ✅ 已播放 = 白色
|
||||
inactiveTrackColor: Colors.white.withAlpha(126), // ✅ 未播放 = 灰色
|
||||
@@ -404,6 +425,10 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
}
|
||||
|
||||
int _getCurrentEpisode(SkywoodDetail detail) {
|
||||
if (_currentEpisode?.episode != null && _currentEpisode!.episode > 0) {
|
||||
return _currentEpisode!.episode;
|
||||
}
|
||||
|
||||
final int? episode =
|
||||
detail.videoInfo?.episode ??
|
||||
detail.videoInfo?.currentEpisode ??
|
||||
@@ -419,18 +444,11 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class _ImageThumbShape extends SliderComponentShape {
|
||||
final String imagePath;
|
||||
final double imageSize;
|
||||
final double imageSize = 16;
|
||||
|
||||
const _ImageThumbShape({
|
||||
required this.imagePath,
|
||||
this.imageSize = 16,
|
||||
});
|
||||
const _ImageThumbShape({required this.imagePath});
|
||||
|
||||
@override
|
||||
Size getPreferredSize(bool isEnabled, bool isDiscrete) {
|
||||
@@ -439,19 +457,19 @@ class _ImageThumbShape extends SliderComponentShape {
|
||||
|
||||
@override
|
||||
void paint(
|
||||
PaintingContext context,
|
||||
Offset center, {
|
||||
required Animation<double> activationAnimation,
|
||||
required Animation<double> enableAnimation,
|
||||
required bool isDiscrete,
|
||||
required TextPainter labelPainter,
|
||||
required RenderBox parentBox,
|
||||
required SliderThemeData sliderTheme,
|
||||
required TextDirection textDirection,
|
||||
required double value,
|
||||
required double textScaleFactor,
|
||||
required Size sizeWithOverflow,
|
||||
}) {
|
||||
PaintingContext context,
|
||||
Offset center, {
|
||||
required Animation<double> activationAnimation,
|
||||
required Animation<double> enableAnimation,
|
||||
required bool isDiscrete,
|
||||
required TextPainter labelPainter,
|
||||
required RenderBox parentBox,
|
||||
required SliderThemeData sliderTheme,
|
||||
required TextDirection textDirection,
|
||||
required double value,
|
||||
required double textScaleFactor,
|
||||
required Size sizeWithOverflow,
|
||||
}) {
|
||||
// 🔥 使用 Image 直接渲染图片
|
||||
final imageWidget = Image.asset(
|
||||
imagePath,
|
||||
@@ -464,29 +482,34 @@ class _ImageThumbShape extends SliderComponentShape {
|
||||
final stream = image.resolve(ImageConfiguration());
|
||||
|
||||
// 添加监听器,但只在图片加载完成后绘制
|
||||
stream.addListener(ImageStreamListener((imageInfo, _) {
|
||||
final rect = Rect.fromCenter(
|
||||
center: center,
|
||||
width: imageSize,
|
||||
height: imageSize,
|
||||
);
|
||||
context.canvas.drawImageRect(
|
||||
imageInfo.image,
|
||||
Rect.fromLTWH(
|
||||
0,
|
||||
0,
|
||||
imageInfo.image.width.toDouble(),
|
||||
imageInfo.image.height.toDouble(),
|
||||
),
|
||||
rect,
|
||||
Paint(),
|
||||
);
|
||||
}, onError: (error, stackTrace) {
|
||||
// 🔥 如果图片加载失败,绘制一个默认圆点
|
||||
final paint = Paint()
|
||||
..color = Colors.white
|
||||
..style = PaintingStyle.fill;
|
||||
context.canvas.drawCircle(center, imageSize / 2, paint);
|
||||
}));
|
||||
stream.addListener(
|
||||
ImageStreamListener(
|
||||
(imageInfo, _) {
|
||||
final rect = Rect.fromCenter(
|
||||
center: center,
|
||||
width: imageSize,
|
||||
height: imageSize,
|
||||
);
|
||||
context.canvas.drawImageRect(
|
||||
imageInfo.image,
|
||||
Rect.fromLTWH(
|
||||
0,
|
||||
0,
|
||||
imageInfo.image.width.toDouble(),
|
||||
imageInfo.image.height.toDouble(),
|
||||
),
|
||||
rect,
|
||||
Paint(),
|
||||
);
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
// 🔥 如果图片加载失败,绘制一个默认圆点
|
||||
final paint = Paint()
|
||||
..color = Colors.white
|
||||
..style = PaintingStyle.fill;
|
||||
context.canvas.drawCircle(center, imageSize / 2, paint);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user