Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 华为p30、华为p30 pro 录制和播放视频异常问题 #56

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added images/video_tape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:better_player_plus/better_player_plus.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';

class TencentCloudChatMessageVideoPlayer extends StatefulWidget {
final V2TimMessage message;
final bool controller;
final bool isSending;

const TencentCloudChatMessageVideoPlayer({
super.key,
required this.message,
required this.controller,
required this.isSending,
});

@override
State<StatefulWidget> createState() => TencentCloudChatMessageVideoPlayerState();
}

enum CurrentVideoType {
online,
local,
}

class CurrentVideoInfo {
final String path;
final CurrentVideoType type;
final double aspectRatio;

CurrentVideoInfo({
required this.path,
required this.type,
required this.aspectRatio,
});
}

class TencentCloudChatMessageVideoPlayerState extends State<TencentCloudChatMessageVideoPlayer> {
final String _tag = "TencentCloudChatMessageVideoPlayer";

BetterPlayerController? _betterPlayerController;

@override
void initState() {
super.initState();
_initializePlayer();
}

Future<void> _initializePlayer() async {
try {
final info = await getMessageInfo();
if (info != null && mounted) {
BetterPlayerDataSource dataSource;
if (info.type == CurrentVideoType.online) {
dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
info.path,
);
} else {
dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.file,
info.path,
);
}

final betterPlayerConfiguration = BetterPlayerConfiguration(
aspectRatio: info.aspectRatio,
fit: BoxFit.contain,
autoPlay: true,
allowedScreenSleep: false,
fullScreenByDefault: false,
controlsConfiguration: const BetterPlayerControlsConfiguration(
enableFullscreen: false,
enablePlayPause: true,
enableProgressBar: true,
enableProgressText: true,
showControlsOnInitialize: false,
enableMute:false,
enableOverflowMenu:false,
enableSkips:false,
),
);

_betterPlayerController = BetterPlayerController(
betterPlayerConfiguration,
betterPlayerDataSource: dataSource,
);

if (mounted) {
setState(() {
});
}
}
} catch (e) {
debugPrint("Video initialization error: $e");
}
}

@override
void dispose() {
_betterPlayerController?.dispose();
super.dispose();
}

Future<CurrentVideoInfo?> getMessageInfo() async {
if (widget.message.elemType == MessageElemType.V2TIM_ELEM_TYPE_VIDEO) {
double aspectRatio = (9 / 16);

if (widget.isSending) {
var lp = widget.message.videoElem!.videoPath ?? "";
if (lp.isNotEmpty) {
console("view sending message video path");
if (File(lp).existsSync() && !kIsWeb) {
return CurrentVideoInfo(path: lp, type: CurrentVideoType.local, aspectRatio: aspectRatio);
}
}
}

if (widget.message.videoElem!.snapshotWidth != null && widget.message.videoElem!.snapshotHeight != null) {
if (widget.message.videoElem!.snapshotHeight != 0) {
aspectRatio = (widget.message.videoElem!.snapshotWidth!) / (widget.message.videoElem!.snapshotHeight!);
}
}

if (TencentUtils.checkString(widget.message.videoElem!.videoPath) != null) {
// 先查本地发送的视频地址
if (File(widget.message.videoElem!.videoPath!).existsSync()) {
console("video: local video path exists");
return CurrentVideoInfo(path: widget.message.videoElem!.videoPath!, type: CurrentVideoType.local, aspectRatio: aspectRatio);
}
} else if (TencentUtils.checkString(widget.message.videoElem!.localVideoUrl) != null) {
// 再查本地下载的视频地址
if (File(widget.message.videoElem!.localVideoUrl!).existsSync()) {
console("video: local url exists");
return CurrentVideoInfo(path: widget.message.videoElem!.localVideoUrl!, type: CurrentVideoType.local, aspectRatio: aspectRatio);
}
} else {
// 最后再查在线地址(todo 使用 getMessageOnlineUrl 查询)
if (widget.message.videoElem != null) {
if (widget.message.videoElem!.snapshotUrl != null) {
console("video: online url ${widget.message.videoElem!.videoUrl}");
return CurrentVideoInfo(
path: widget.message.videoElem!.videoUrl!,
type: CurrentVideoType.online,
aspectRatio: aspectRatio,
);
}
}
if (!kIsWeb) {
V2TimValueCallback<V2TimMessageOnlineUrl> urlres = await TencentImSDKPlugin.v2TIMManager.getMessageManager().getMessageOnlineUrl(msgID: widget.message.msgID ?? "");
if (urlres.data != null) {
if (urlres.data?.videoElem != null) {
if (TencentUtils.checkString(urlres.data?.videoElem?.videoUrl) != null) {
console("view video online url ${urlres.data?.videoElem?.videoUrl}");
return CurrentVideoInfo(path: urlres.data!.videoElem!.videoUrl!, type: CurrentVideoType.online, aspectRatio: aspectRatio);
}
}
}
}
}
} else {
console("The component received a non-video message parameter. please check");
}
console("has no view video source. please check");
return null;
}

console(String log) {
print("$_tag, $log");
}

@override
Widget build(BuildContext context) {
if (widget.message.hasRiskContent == true) {
return const Center(
child: Text(
"Risk Video",
style: TextStyle(color: Colors.white),
),
);
}

if (_betterPlayerController == null) {
return Container();
}

return AspectRatio(
aspectRatio: _betterPlayerController!.videoPlayerController?.value.aspectRatio ?? 9 / 16,
child: BetterPlayer(
controller: _betterPlayerController!,
),
);
}
}
105 changes: 0 additions & 105 deletions lib/ui/views/TIMUIKitChat/TIMUIKitTextField/intl_camer_picker.dart

This file was deleted.

Loading