Flutter 'install-time' Delivery video Play Error

19 views Asked by At

I'm using play asset delivery method to play my video in Flutter. It's work's blow 100MB video size. But i have 600MB size video file. if i play this(600MB) file, App get auto close.

This is my code

import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
import 'package:rxdart/rxdart.dart';

class FlutterPlayAssetDelivery {
  static const String _methodGetAsset = "getAssetFile";
  static const MethodChannel _channel =
  MethodChannel('flutter_play_asset_delivery');

  static Future<File> getAssetFile(String asset) async {
    try {
      final path = await getAbsoluteFilePath(asset);
      final file = File(path);
      return file;
    } catch (e) {
      throw Exception("Asset file $asset not found: $e");
    }
  }

  static Future<String> getAbsoluteFilePath(String asset) async {
    return (await _channel.invokeMethod(_methodGetAsset, asset)) as String;
  }
}

class VideoScreen extends StatefulWidget {
  @override
  _VideoScreenState createState() => _VideoScreenState();
}

class _VideoScreenState extends State<VideoScreen> {
  ChewieController? _chewieController;
  late Future<File> video;
  late BehaviorSubject<bool> _videoInitializedSubject;
  late VideoPlayerController _videoPlayerController;

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

    _videoInitializedSubject = BehaviorSubject<bool>.seeded(false);

    video = FlutterPlayAssetDelivery.getAssetFile("intro.mp4");
    video.then((File filePath) async {
      if (filePath.existsSync()) {
        _videoPlayerController = VideoPlayerController.file(filePath);

        await _videoPlayerController.initialize();

        if (mounted) {
          setState(() {
            _chewieController = ChewieController(
              videoPlayerController: _videoPlayerController,
              autoPlay: false,
              looping: false,
              // You can customize other options here
            );
            _videoInitializedSubject.add(true);
          });
        }
      }
    });
  }

  @override
  void dispose() {
    _chewieController?.dispose();
    _videoPlayerController.dispose(); // Dispose the video player controller
    _videoInitializedSubject.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'History',
          style: TextStyle(
            color: Colors.white,
          ),
        ),
        backgroundColor: const Color(0xFF3371A5),
        leading: IconButton(
          icon: const Icon(Icons.arrow_back, color: Colors.white),
          onPressed: () {
            // Stop the video player when the back arrow is pressed
            _videoPlayerController.pause();
            Navigator.pop(context);
          },
        ),
      ),
      body: StreamBuilder<bool>(
        stream: _videoInitializedSubject.stream,
        builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting ||
              !snapshot.hasData ||
              !snapshot.data!) {
            return const Center(
              child: CircularProgressIndicator(),
            );
          } else if (_chewieController != null) {
            return Chewie(
              controller: _chewieController!,
            );
          } else {
            return const Center(
              child: CircularProgressIndicator(),
            );
          }
        },
      ),
    );
  }
}
plugins -

dependencies:
  flutter:
    sdk: flutter
  webview_flutter_plus: ^0.3.0+2
  #  audioplayers_darwin: ^5.0.1
  flutter_launcher_icons: ^0.13.1
  cupertino_icons: ^1.0.2
  url_launcher: ^6.1.12
  share_plus: ^7.1.0
  shared_preferences: ^2.2.2
  flutter_play_asset_delivery: ^0.0.2
  change_app_package_name: ^1.1.0
  photo_view: ^0.14.0
  rxdart: ^0.27.7
  chewie: ^1.3.6

When implementing install-time delivery of large video files in a Flutter application, it's essential to optimize the user experience by efficiently handling video playback. Flutter provides a convenient way to achieve this through the use of the "flutter_play_asset_delivery" package. This method involves fetching the video asset during install time, allowing for smoother playback and reduced loading times. To implement this, developers can utilize the "Chewie" and "VideoPlayer" packages to seamlessly integrate video playback functionalities.

How to play large size of video file Using play asset delivery !

0

There are 0 answers