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

Feature parity with audio players like methods (pause, onComplete, onDuration / onCurrentPosition, seek,...) #7

Open
sachaarbonel opened this issue Nov 29, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@sachaarbonel
Copy link

sachaarbonel commented Nov 29, 2019

Hi @frideosapps thank's for this wonderful library, this is exactly what I was looking for. My use case is that I would like to sync audio and text (mostly), save the progress of the user, etc ... I think I can achieve that with the callbacks (onStart => play song, onPause => pause song, ... )

First, if I understand the docs correctly, I can only do play (startStages),rewind (resetStages), and skip next stage (getNextStage). It would be nice to have on the low level widget StagedObject a method like getPreviousStage and on an upper level have StagedWidget, have the corresponding utility methods and callbacks .

Second, for the features like (pause, onComplete, onDuration / onCurrentPosition, seek) I guess it will have some repercussions on StreamedObject and ValueBuilder to have more control over the stream.

What do you think ? I'm playing around your code right now to make a PR but for some reason I can't reset the player.

Here is my raw code

import 'package:frideos/frideos.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var reset = "reset";
  Stage stage;
  @override
  void initState() {
    staged
      ..setStagesMap(stagesMap)
      ..startStages();
    stage = staged.getStage(0);
    super.initState();
  }

  @override
  void dispose() {
    staged.dispose();
    super.dispose();
  }

  var staged = StagedObject();
  var stagesMap = <int, Stage>{
    0: Stage(
        widget: Container(
          key: const Key('0'),
          child: const Text('Stage 0'),
        ),
        time: 2000,
        onShow: () {
          //tester.pump();
        }),
    1: Stage(
        widget: Container(
          key: const Key('1'),
          child: const Text(
            'Stage 1',
            // style: TextStyle(fontSize: 50),
          ),
        ),
        time: 2000,
        onShow: () {}),
    2: Stage(
        widget: Container(
          key: const Key('2'),
          child: const Text(
            'Stage 2',
            // style: TextStyle(fontSize: 50),
          ),
        ),
        time: 2000,
        onShow: () {}),
  };

// var stagesMap = ;
  @override
  Widget build(BuildContext context) {
    assert(stage != null);
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.refresh),
        onPressed: () {
         
              staged
            //  ..setStagesMap(stagesMap)
            ..resetStages();
          setState(() {
            reset = "reset";
            staged = staged;
          });
          print(reset);
      

          // print(reset);
        },
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Center(
            child: ValueBuilder(
                streamed: staged,
                builder: (context, snapshot) => snapshot.data),
          ),
        ],
      ),
    );
  }
}
@frideosapps
Copy link
Owner

frideosapps commented Dec 5, 2019

Hello @sachaarbonel, your requests are interesting, and I think I can take them into account for one of the next releases. Any PR is welcome and really appreciated. I've just fixed your code:

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  
  final staged = StagedObject(); // This is final, it won't change.

  var reset = "reset";
  Stage stage;

  @override
  void initState() {
    staged
      ..setStagesMap(stagesMap)
      ..startStages();
    stage = staged.getStage(0);
    super.initState();
  }

  @override
  void dispose() {
    staged.dispose();
    super.dispose();
  }


  var stagesMap = <int, Stage>{
    0: Stage(
        widget: Container(
          key: const Key('0'),
          child: const Text('Stage 0'),
        ),
        time: 2000,
        onShow: () {
          //tester.pump();
        }),
    1: Stage(
        widget: Container(
          key: const Key('1'),
          child: const Text(
            'Stage 1',
            // style: TextStyle(fontSize: 50),
          ),
        ),
        time: 2000,
        onShow: () {}),
    2: Stage(
        widget: Container(
          key: const Key('2'),
          child: const Text(
            'Stage 2',
            // style: TextStyle(fontSize: 50),
          ),
        ),
        time: 2000,
        onShow: () {}),
  };

// var stagesMap = ;
  @override
  Widget build(BuildContext context) {
    assert(stage != null);
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.refresh),
        onPressed: () {         

          // We are using streams, no need of set state
          staged.resetStages();
          staged.startStages();

        /*
          staged
            //  ..setStagesMap(stagesMap)
            ..resetStages();
          setState(() {
            reset = "reset";
            staged = staged;
          });
          print(reset);
        */          
        },
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Center(
            child: ValueBuilder(
                streamed: staged,
                builder: (context, snapshot) => snapshot.data),
          ),
        ],
      ),
    );
  }
}

@frideosapps frideosapps added the enhancement New feature or request label Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants