cached_video_preview 1.0.6 copy "cached_video_preview: ^1.0.6" to clipboard
cached_video_preview: ^1.0.6 copied to clipboard

Flutter plugin that can help you get remote or local video preview image and cache it.

example/lib/main.dart

import 'dart:io';

import 'package:cached_video_preview/cached_video_preview.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'cached_video_preview Demo',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Example'),
        ),
        body: Column(
          children: <Widget>[
            Expanded(
              child: CachedVideoPreviewWidget(
                path: 'https://www.youtube.com/watch?v=b_sQ9bMltGU',
                type: SourceType.remote,
                remoteImageBuilder: (BuildContext context, url) =>
                    Image.network(url),
              ),
            ),
            Expanded(
              child: CachedVideoPreviewWidget(
                path:
                    'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
                type: SourceType.remote,
                remoteImageBuilder: (BuildContext context, url) =>
                    Image.network(url),
                // Add custom Http Headers,
                httpHeaders: const <String, String>{},
              ),
            ),
            Expanded(
              child: FutureBuilder<File>(
                future: _loadVideoFileFromAsset(),
                builder: (_, snapshot) => snapshot.hasData
                    ? CachedVideoPreviewWidget(
                        path: snapshot.requireData.path,
                        type: SourceType.local,
                        fileImageBuilder: (context, bytes) =>
                            Image.memory(bytes),
                      )
                    : const SizedBox.shrink(),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Future<File> _loadVideoFileFromAsset() async {
    Directory directory = await getApplicationDocumentsDirectory();
    final filePath = join(directory.path, 'video.mp4');
    ByteData data = await rootBundle.load('assets/video.mp4');
    List<int> bytes =
        data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
    return File(filePath).writeAsBytes(bytes);
  }
}
27
likes
125
points
263
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin that can help you get remote or local video preview image and cache it.

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, metadata_fetch, moor, moor_flutter, path, path_provider, platform, sqlite3_flutter_libs, video_thumbnail

More

Packages that depend on cached_video_preview