Code Monkey home page Code Monkey logo

Comments (5)

jonasN5 avatar jonasN5 commented on July 21, 2024

+1, atm we can't unsubscribe to progress callback.

from videocompress.

marceloreis13 avatar marceloreis13 commented on July 21, 2024

I'm facing the same problem

from videocompress.

hectorAguero avatar hectorAguero commented on July 21, 2024

Hi, probably this issue is different, but I can't make work the readme example for subscribe to progress, so for anyone that doesn't understand how to make a workaround for that error in subscription, I made this example based on the example file.

Also, I have the same question than if is neccesary to unsubscribe to compressProgress$

Edit: Added _videoCompress.dispose() to the code.

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:video_compress/video_compress.dart';
import 'package:image_picker/image_picker.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _pathVideo;
  final _streamController = StreamController<int>();
  IVideoCompress _videoCompress;

  @override
  void initState() {
    super.initState();
    _videoCompress = vc.VideoCompress;
    _videoCompress.compressProgress$.subscribe((event) {
      _streamController.add(event.round());
    });
  }

  @override
  void dispose() {
    _streamController.close();
    _videoCompress.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Video Compress')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            StreamBuilder<int>(
              stream: _streamController.stream,
              initialData: 0,
              builder: (context, snapshot) {
                if (snapshot.data == 0 && _pathVideo == null)
                  return Text('Select Video...');
                if (snapshot.data == 100) return Text(_pathVideo ?? '');
                return Text('Compressing video ${snapshot.data}%');
              },
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          if (_pathVideo != null) await File(_pathVideo).delete();
          setState(() => _pathVideo = null);
          final file =
              await ImagePicker().getVideo(source: ImageSource.gallery);
          if (file != null) {
            _streamController.add(0);
            final info = await VideoCompress.compressVideo(file.path,
                quality: VideoQuality.MediumQuality, includeAudio: true);
            if (info != null) setState(() => _pathVideo = info.path);
          } else {
            _streamController.add(0);
          }
        },
        tooltip: 'Compress Video',
        child: const Icon(Icons.video_library),
      ),
    );
  }
}`

from videocompress.

hyobbb avatar hyobbb commented on July 21, 2024

Same issue. Any notice??

from videocompress.

jonataslaw avatar jonataslaw commented on July 21, 2024

Fixed on 2.1.1

from videocompress.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.