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

feat: adding fileName field on controller and bubble #215

Merged
merged 18 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 24 additions & 7 deletions lib/src/controllers/chat/ds_video_message_bubble.controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class DSVideoMessageBubbleController {
final String url;
final int mediaSize;
final Map<String, String?>? httpHeaders;
final String fileName;

DSVideoMessageBubbleController({
required this.uniqueId,
required this.url,
required this.mediaSize,
required this.fileName,
this.httpHeaders,
}) {
setThumbnail();
Expand All @@ -44,6 +46,17 @@ class DSVideoMessageBubbleController {
final thumbnailFile = File(await getFullThumbnailPath());
if (await thumbnailFile.exists()) {
thumbnail.value = thumbnailFile.path;
} else {
getVideoAndSetThumbnail();
}
}

Future<void> getVideoAndSetThumbnail() async {
RaulRodrigo06 marked this conversation as resolved.
Show resolved Hide resolved
final temporaryPath = (await getTemporaryDirectory()).path;
RaulRodrigo06 marked this conversation as resolved.
Show resolved Hide resolved
final localPath = temporaryPath.replaceAll('cache', 'files');
final file = File('$localPath/$fileName');
if (await file.exists()) {
_generateThumbnail(file.path);
}
}

Expand Down Expand Up @@ -89,13 +102,7 @@ class DSVideoMessageBubbleController {
}
}

final thumbnailPath = await getFullThumbnailPath();

await FFmpegKit.execute(
'-hide_banner -y -i "${outputFile.path}" -vframes 1 "$thumbnailPath"',
);

thumbnail.value = thumbnailPath;
_generateThumbnail(outputFile.path);
} catch (_) {
hasError.value = true;

Expand All @@ -110,4 +117,14 @@ class DSVideoMessageBubbleController {
isDownloading.value = false;
}
}

Future<void> _generateThumbnail(String path) async {
final thumbnailPath = await getFullThumbnailPath();

await FFmpegKit.execute(
'-hide_banner -y -i "$path" -vframes 1 "$thumbnailPath"',
);

thumbnail.value = thumbnailPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class DSVideoMessageBubble extends StatefulWidget {
/// Indicates if the HTTP Requests should be authenticated or not.
final bool shouldAuthenticate;

/// The title of the video
final String? title;

/// Card for the purpose of triggering a video to play.
///
/// This widget is intended to display a video card from a url passed in the [url] parameter.
Expand All @@ -60,6 +63,7 @@ class DSVideoMessageBubble extends StatefulWidget {
required this.appBarText,
required this.uniqueId,
required this.mediaSize,
this.title,
this.appBarPhotoUri,
this.text,
this.borderRadius = const [DSBorderRadius.all],
Expand All @@ -83,6 +87,7 @@ class _DSVideoMessageBubbleState extends State<DSVideoMessageBubble>
url: widget.url,
mediaSize: widget.mediaSize,
httpHeaders: widget.shouldAuthenticate ? DSAuthService.httpHeaders : null,
fileName: widget.title ?? '',
RaulRodrigo06 marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/widgets/utils/ds_card.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class DSCard extends StatelessWidget {
text: media.text,
borderRadius: borderRadius,
style: style,
title: media.title ?? '',
uniqueId: messageId ?? DateTime.now().toIso8601String(),
mediaSize: size,
shouldAuthenticate: shouldAuthenticate,
Expand Down