Compare commits

..

1 Commits

Author SHA1 Message Date
3d2c6a122a feat: 充电视频试看 2024-02-16 21:30:29 +08:00
6 changed files with 68 additions and 33 deletions

View File

@ -229,7 +229,9 @@ class VideoContent extends StatelessWidget {
),
if (crossAxisCount > 1) ...[
const SizedBox(height: 2),
VideoStat(videoItem: videoItem, crossAxisCount: crossAxisCount),
VideoStat(
videoItem: videoItem,
),
],
if (crossAxisCount == 1) const SizedBox(height: 4),
Row(
@ -290,14 +292,10 @@ class VideoContent extends StatelessWidget {
color: Theme.of(context).colorScheme.outline,
),
),
Expanded(
flex: 1,
child: VideoStat(
videoItem: videoItem,
crossAxisCount: crossAxisCount,
),
VideoStat(
videoItem: videoItem,
),
// const Spacer(),
const Spacer(),
],
if (videoItem.goto == 'av' && crossAxisCount != 1) ...[
VideoPopupMenu(
@ -319,12 +317,10 @@ class VideoContent extends StatelessWidget {
class VideoStat extends StatelessWidget {
final dynamic videoItem;
final int crossAxisCount;
const VideoStat({
Key? key,
required this.videoItem,
required this.crossAxisCount,
}) : super(key: key);
@override
@ -341,7 +337,7 @@ class VideoStat extends StatelessWidget {
danmu: videoItem.stat.danmu,
),
if (videoItem is RecVideoItemModel) ...<Widget>[
crossAxisCount > 1 ? const Spacer() : const SizedBox(width: 8),
const Spacer(),
RichText(
maxLines: 1,
text: TextSpan(

View File

@ -1,5 +1,3 @@
import 'package:pilipala/utils/id_utils.dart';
class RecVideoItemAppModel {
RecVideoItemAppModel({
this.id,
@ -52,15 +50,14 @@ class RecVideoItemAppModel {
? json['player_args']['aid']
: int.parse(json['param'] ?? '-1');
aid = json['player_args'] != null ? json['player_args']['aid'] : -1;
bvid = json['player_args'] != null
? IdUtils.av2bv(json['player_args']['aid'])
: '';
bvid = null;
cid = json['player_args'] != null ? json['player_args']['cid'] : -1;
pic = json['cover'];
stat = RcmdStat.fromJson(json);
// 改用player_args中的duration作为原始数据秒数
duration =
json['player_args'] != null ? json['player_args']['duration'] : -1;
duration = json['player_args'] != null
? json['player_args']['duration']
: -1;
//duration = json['cover_right_text'];
title = json['title'];
owner = RcmdOwner.fromJson(json);

View File

@ -34,6 +34,7 @@ class PlayUrlModel {
String? seekParam;
String? seekType;
Dash? dash;
List<Durl>? durl;
List<FormatItem>? supportFormats;
// String? highFormat;
int? lastPlayTime;
@ -52,7 +53,8 @@ class PlayUrlModel {
videoCodecid = json['video_codecid'];
seekParam = json['seek_param'];
seekType = json['seek_type'];
dash = Dash.fromJson(json['dash']);
dash = json['dash'] != null ? Dash.fromJson(json['dash']) : null;
durl = json['durl']?.map<Durl>((e) => Durl.fromJson(e)).toList();
supportFormats = json['support_formats'] != null
? json['support_formats']
.map<FormatItem>((e) => FormatItem.fromJson(e))
@ -250,3 +252,30 @@ class Flac {
audio = json['audio'] != null ? AudioItem.fromJson(json['audio']) : null;
}
}
class Durl {
Durl({
this.order,
this.length,
this.size,
this.ahead,
this.vhead,
this.url,
});
int? order;
int? length;
int? size;
String? ahead;
String? vhead;
String? url;
Durl.fromJson(Map<String, dynamic> json) {
order = json['order'];
length = json['length'];
size = json['size'];
ahead = json['ahead'];
vhead = json['vhead'];
url = json['url'];
}
}

View File

@ -102,12 +102,15 @@ class _ImagePreviewState extends State<ImagePreview>
);
}
// 隐藏状态栏,避免遮挡图片内容
// 设置状态栏图标透明
setStatusBar() async {
if (Platform.isIOS || Platform.isAndroid) {
if (Platform.isIOS) {
await StatusBarControl.setHidden(true,
animation: StatusBarAnimation.SLIDE);
}
if (Platform.isAndroid) {
await StatusBarControl.setColor(Colors.transparent);
}
}
@override

View File

@ -229,9 +229,11 @@ class VideoDetailController extends GetxController
seekTo: seekToTime ?? defaultST,
duration: duration ?? Duration(milliseconds: data.timeLength ?? 0),
// 宽>高 水平 否则 垂直
direction: (firstVideo.width! - firstVideo.height!) > 0
? 'horizontal'
: 'vertical',
direction: firstVideo.width != null && firstVideo.height != null
? ((firstVideo.width! - firstVideo.height!) > 0
? 'horizontal'
: 'vertical')
: null,
bvid: bvid,
cid: cid.value,
enableHeart: enableHeart,
@ -248,6 +250,21 @@ class VideoDetailController extends GetxController
var result = await VideoHttp.videoUrl(cid: cid.value, bvid: bvid);
if (result['status']) {
data = result['data'];
if (data.acceptDesc!.isNotEmpty && data.acceptDesc!.contains('试看')) {
SmartDialog.showToast(
'该视频为专属视频,仅提供试看',
displayTime: const Duration(seconds: 3),
);
videoUrl = data.durl!.first.url!;
audioUrl = '';
defaultST = Duration.zero;
firstVideo = VideoItem();
if (autoPlay.value) {
await playerInit();
isShowCover.value = false;
}
return result;
}
final List<VideoItem> allVideosList = data.dash!.video!;
try {
// 当前可播放的最高质量视频

View File

@ -20,15 +20,11 @@ class AudioSessionHandler {
session.interruptionEventStream.listen((event) {
final player = PlPlayerController.getInstance();
if (event.begin) {
if (player.playerStatus != PlayerStatus.playing) return;
switch (event.type) {
case AudioInterruptionType.duck:
player.setVolume(player.volume.value * 0.5);
break;
case AudioInterruptionType.pause:
player.pause(isInterrupt: true);
_playInterrupted = true;
break;
case AudioInterruptionType.unknown:
player.pause(isInterrupt: true);
_playInterrupted = true;
@ -40,7 +36,7 @@ class AudioSessionHandler {
player.setVolume(player.volume.value * 2);
break;
case AudioInterruptionType.pause:
if (_playInterrupted) player.play();
if (_playInterrupted) PlPlayerController.getInstance().play();
break;
case AudioInterruptionType.unknown:
break;
@ -51,10 +47,7 @@ class AudioSessionHandler {
// 耳机拔出暂停
session.becomingNoisyEventStream.listen((_) {
final player = PlPlayerController.getInstance();
if (player.playerStatus == PlayerStatus.playing) {
player.pause();
}
PlPlayerController.getInstance().pause();
});
}
}