Skip to content

Commit

Permalink
fix(ui): namespace not specified for video_thumbnail package. (#2049)
Browse files Browse the repository at this point in the history
  • Loading branch information
xsahil03x authored Nov 18, 2024
1 parent 099667f commit 4b062b2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
7 changes: 7 additions & 0 deletions packages/stream_chat_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Upcoming

🐞 Fixed

- [[#2030]](https://github.com/GetStream/stream-chat-flutter/issues/2030) Fixed `video_thumbnail`
Namespace not specified.

## 8.2.0

✅ Added
Expand Down
45 changes: 24 additions & 21 deletions packages/stream_chat_flutter/lib/src/video/video_service.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'dart:async';
import 'dart:ui' as ui;

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:get_thumbnail_video/index.dart';
import 'package:get_thumbnail_video/video_thumbnail.dart';
import 'package:stream_chat_flutter/src/utils/device_segmentation.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:thumblr/thumblr.dart' as thumblr;
import 'package:video_thumbnail/video_thumbnail.dart';

///
// ignore: prefer-match-file-name
Expand Down Expand Up @@ -40,29 +41,27 @@ class _IVideoService {
int timeMs = 0,
int quality = 10,
}) async {
if (kIsWeb || video == null) {
final placeholder = await generatePlaceholderThumbnail();
return placeholder;
}
if (isDesktopDevice) {
try {
// If the video path is not supplied, return a placeholder image.
if (video == null) return generatePlaceholderThumbnail();

try {
// If the device is a desktop, use thumblr to generate the thumbnail.
if (isDesktopDevice) {
final thumbnail = await thumblr.generateThumbnail(filePath: video);
final byteData = await thumbnail.image.toByteData(
format: ui.ImageByteFormat.png,
);
final bytesList = byteData?.buffer.asUint8List() ?? Uint8List(0);
if (bytesList.isNotEmpty) {

final bytesList = byteData?.buffer.asUint8List();
if (bytesList != null && bytesList.isNotEmpty) {
return bytesList;
} else {
return await generatePlaceholderThumbnail();
}
} catch (e) {
// If the thumbnail generation fails, return a placeholder image.
final placeholder = await generatePlaceholderThumbnail();
return placeholder;

return await generatePlaceholderThumbnail();
}
} else if (isMobileDevice) {
return VideoThumbnail.thumbnailData(

// Otherwise, use the VideoThumbnail package to generate the thumbnail.
return await VideoThumbnail.thumbnailData(
video: video,
headers: headers,
imageFormat: imageFormat,
Expand All @@ -71,14 +70,18 @@ class _IVideoService {
timeMs: timeMs,
quality: quality,
);
} catch (_) {
// If the thumbnail generation fails, return a placeholder image.
return generatePlaceholderThumbnail();
}
throw Exception('Could not generate thumbnail');
}

/// Generates a placeholder thumbnail by loading placeholder.png from assets.
Future<Uint8List> generatePlaceholderThumbnail() async {
final placeholder = await rootBundle
.load('packages/stream_chat_flutter/images/placeholder.png');
final placeholder = await rootBundle.load(
'packages/stream_chat_flutter/images/placeholder.png',
);

return placeholder.buffer.asUint8List();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'dart:ui' as ui;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get_thumbnail_video/index.dart';
import 'package:stream_chat_flutter/src/video/video_service.dart';
import 'package:video_thumbnail/video_thumbnail.dart' show ImageFormat;

/// {@template video_thumbnail_image}
/// A custom [ImageProvider] class for loading video thumbnails as images in
Expand Down
2 changes: 1 addition & 1 deletion packages/stream_chat_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies:
flutter_markdown: ^0.7.2+1
flutter_portal: ^1.1.4
flutter_svg: ^2.0.10+1
get_thumbnail_video: ^0.7.3
http_parser: ^4.0.2
image_gallery_saver_plus: ^3.0.5
image_picker: ^1.1.2
Expand All @@ -46,7 +47,6 @@ dependencies:
thumblr: ^0.0.4
url_launcher: ^6.3.0
video_player: ^2.8.7
video_thumbnail: ^0.5.3

flutter:
plugin:
Expand Down

0 comments on commit 4b062b2

Please sign in to comment.