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

Cant open audio from local #10

Closed
worldwidee opened this issue Apr 30, 2022 · 2 comments
Closed

Cant open audio from local #10

worldwidee opened this issue Apr 30, 2022 · 2 comments

Comments

@worldwidee
Copy link

When i want to run local mp3 file it doesnt run/work. However player.network is working successfully. I am working on windows. There is no setup on windows for dart_vlc.

var player = Player.create(
        media: PlayerMedia.file(mp3FilePath), autoPlay: false, once: true)
      ..init();

I create a stateful widget same as yours example. everything is working if i change the player part instead :

var player = Player.create(
        media: PlayerMedia.network("https://archive.org/download/s0v5kiwcwp1zaps7pdwjtp5o8e6clmevdnewngnd/JSJ_385_Panel.mp3"), autoPlay: false, once: true)
      ..init();

my stateful widget:

class AudioPlayer extends StatefulWidget {
  String path;
  Color bgColor, textColor;
  double width, height;
  AudioPlayer(
      {Key? key,
      required this.path,
      required this.bgColor,
      required this.textColor,
      required this.width,
      required this.height})
      : super(key: key);

  @override
  State<AudioPlayer> createState() =>
      _AudioPlayerState(path, bgColor, textColor);
}

class _AudioPlayerState extends State<AudioPlayer> {
  String path;
  Color bgColor, textColor;
  _AudioPlayerState(this.path, this.bgColor, this.textColor) {
    player = Player.create(
        media: PlayerMedia.file(path), autoPlay: false, once: true)
      ..init();
  }
  late PlayerController player;
  bool _changingPosition = false;
  bool loading = false;
  Duration _position = Duration.zero;
  double get position {
    if (player.duration.inSeconds == 0) {
      return 0;
    }
    if (_changingPosition) {
      return _position.inSeconds * 100 / player.duration.inSeconds;
    } else {
      return player.position.inSeconds * 100 / player.duration.inSeconds;
    }
  }

  @override
  void dispose() {
    player.stop();
    player.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: widget.width,
      height: widget.height,
      decoration: BoxDecoration(
          color: bgColor, borderRadius: BorderRadius.circular(20)),
      padding: EdgeInsets.symmetric(horizontal: widget.width * 0.05),
      child: Row(children: [
        SizedBox(
          width: widget.height * 0.8,
          height: widget.height * 0.8,
          child: StreamBuilder(
            stream: player.positionStream,
            builder: (context, snapshot) {
              return CircularProgressIndicator(
                strokeWidth: 1,
                color: Colors.teal,
                value: loading
                    ? null
                    : player.position.inSeconds /
                        max(player.duration.inSeconds, 0.01),
              );
            },
          ),
        ),
        IconButton(
            onPressed: () {
              setState(() {
                player.toggle();
              });
            },
            icon: StreamBuilder(
              stream: player.positionStream,
              builder: (context, snapshot) {
                return player.playing
                    ? Icon(
                        Icons.pause,
                        color: textColor,
                        size: appFonts.icon_S(),
                      )
                    : Icon(
                        Icons.play_arrow,
                        color: textColor,
                        size: appFonts.icon_S(),
                      );
              },
            )),
        Expanded(
          child: StreamBuilder(
              stream: player.positionStream,
              builder: (context, AsyncSnapshot<Duration> snapshot) {
                loading = false;
                return CupertinoSlider(
                  value: position,
                  min: 0,
                  max: 100,
                  onChangeStart: (double value) {
                    _changingPosition = true;
                  },
                  onChangeEnd: (double value) {
                    _changingPosition = false;
                  },
                  onChanged: (double value) {
                    setState(() {
                      loading = true;
                      _position = Duration(
                          seconds: ((value / 100) * player.duration.inSeconds)
                              .toInt());
                      player.position = _position;
                    });
                  },
                );
              }),
        ),
        IconButton(
            onPressed: () {
              setState(() {
                if (player.volume > 0) {
                  player.volume = 0.0;
                } else {
                  player.volume = 1.0;
                }
              });
            },
            icon: StreamBuilder(
              stream: player.positionStream,
              builder: (context, snapshot) {
                return player.volume == 0
                    ? Icon(
                        Icons.volume_mute,
                        color: textColor,
                        size: appFonts.icon_S(),
                      )
                    : Icon(
                        Icons.volume_up,
                        color: textColor,
                        size: appFonts.icon_S(),
                      );
              },
            ))
      ]),
    );
  }
}
@mohamadlounnas
Copy link
Member

an update coming

@mohamadlounnas
Copy link
Member

packege updated
it should work know
u can use (depend on dart_vlc, and just_audio)
https://pub.dev/packages/kplayer
or (only audioplayers)
https://pub.dev/packages/kplayer_with_audioplayers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants