颤振擦洗音频

时间:2019-05-14 02:10:02

标签: dart flutter

所以我试图移动滑块以手动调整音频文件的位置。

现在我可以使用大多数音频功能了。

按下滑块时,每次都会从头开始。

我尝试了您在下面看到的代码。

bool _isPlaying = false;
  bool _isPaused = false;
  FlutterSound _sound = FlutterSound();
  double _playPosition;
  double sliderCurrentPosition;
  double endoftrack;
  Stream<PlayStatus> _playerSubscription;

  void initState() {
    super.initState();
    _sound = FlutterSound();
    _playPosition = 0;
    endoftrack = 1.0;
  }

  void _stop() async {
    await _sound.stopPlayer();
    setState(() {
      _isPlaying = false;
    });
  }

  void _play() async {
    await _sound.startPlayer(widget.snapshot.data["audio"]);
    debugPrint("Player Started");
    _playerSubscription = _sound.onPlayerStateChanged
      ..listen((e) {
      if (e != null) {
        sliderCurrentPosition = e.currentPosition;
        endoftrack = e.duration;
        setState(() => _playPosition = e.currentPosition/ e.duration);
      }
    });
    setState(() => _isPlaying = true);
  }    

Slider(
                        value: _playPosition,
                        min: 0.0,
                        onChanged: (double value) async{
                          await _sound.seekToPlayer(value.toInt());
                        },
                        divisions: endoftrack.toInt()
                      ),

0 个答案:

没有答案