florent37 / Flutter-AssetsAudioPlayer

Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
https://pub.dartlang.org/packages/assets_audio_player
Apache License 2.0
757 stars 368 forks source link

Play sound as soon as we press the play button. Now it takes some time to play the sound which is not good for my app #541

Open Kashish-Manandhar opened 3 years ago

Kashish-Manandhar commented 3 years ago

Describe the feature you'd like A clear and concise description of what you want to happen.

Mayb3Nots commented 3 years ago

What type of audio format are you using? local or online? If its online make sure the cache is turn off since if its on it will take some time to load before playing. If its offline you can try the app in production mode since reading/writing in debug mode is slower.

Kashish-Manandhar commented 3 years ago

I am using the audio from the assets folder

Mayb3Nots commented 3 years ago

In that case have you tired testing in production mode? If its still slow what is the time of loading?

yubarajshrestha commented 3 years ago

What type of audio format are you using? local or online? If its online make sure the cache is turn off since if its on it will take some time to load before playing. If its offline you can try the app in production mode since reading/writing in debug mode is slower.

From where can I turn off the cache? any samples?

Mayb3Nots commented 3 years ago

What type of audio format are you using? local or online? If its online make sure the cache is turn off since if its on it will take some time to load before playing. If its offline you can try the app in production mode since reading/writing in debug mode is slower.

From where can I turn off the cache? any samples?

Under Audio there is a cache property. By default it is disabled.

yubarajshrestha commented 3 years ago

What type of audio format are you using? local or online? If its online make sure the cache is turn off since if its on it will take some time to load before playing. If its offline you can try the app in production mode since reading/writing in debug mode is slower.

From where can I turn off the cache? any samples?

Under Audio there is a cache property. By default it is disabled.

Didn't help. Is this happening because of debug mode?

Mayb3Nots commented 3 years ago

Can you provide some code sample and video

yubarajshrestha commented 3 years ago

This is global.

library library.globals;

import 'package:assets_audio_player/assets_audio_player.dart';

class Player {
  AssetsAudioPlayer player = AssetsAudioPlayer.withId('saylo_player');

  static final Map<String, Player> _cache = {};

  Player._createInstance();

  factory Player() {
    if (!_cache.containsKey("player")) {
      Player instance = Player._createInstance();
      _cache["player"] = instance;
      instance.player.onErrorDo = (handler) {
        handler.player.stop();
      };
    }
    return _cache['player'];
  }
}

AssetsAudioPlayer player = Player().player;

Inside Provider...

player.open(
      Playlist(
        audios: songs
            .map<Audio>(
              (song) => Audio.network(
                song.songUrl,
                metas: Metas(
                  id: song.id,
                  title: song.name,
                  artist: song.artist ?? "artist",
                  album: song.album ?? "album",
                  image: MetasImage.network(song.coverUrl),
                ),
              ),
            )
            .toList(),
      ),
      showNotification: true,
      autoStart: false,
);
player.play();

Also it plays twice sometimes. And can't stop without closing app.

Mayb3Nots commented 3 years ago

This is global.

library library.globals;

import 'package:assets_audio_player/assets_audio_player.dart';

class Player {
  AssetsAudioPlayer player = AssetsAudioPlayer.withId('saylo_player');

  static final Map<String, Player> _cache = {};

  Player._createInstance();

  factory Player() {
    if (!_cache.containsKey("player")) {
      Player instance = Player._createInstance();
      _cache["player"] = instance;
      instance.player.onErrorDo = (handler) {
        handler.player.stop();
      };
    }
    return _cache['player'];
  }
}

AssetsAudioPlayer player = Player().player;

Inside Provider...

player.open(
      Playlist(
        audios: songs
            .map<Audio>(
              (song) => Audio.network(
                song.songUrl,
                metas: Metas(
                  id: song.id,
                  title: song.name,
                  artist: song.artist ?? "artist",
                  album: song.album ?? "album",
                  image: MetasImage.network(song.coverUrl),
                ),
              ),
            )
            .toList(),
      ),
      showNotification: true,
      autoStart: false,
);
player.play();

Also it plays twice sometimes. And can't stop without closing app.

Looks good to me, however you might wanna use auto start insead of manually calling play.

yubarajshrestha commented 3 years ago

This is global.

library library.globals;

import 'package:assets_audio_player/assets_audio_player.dart';

class Player {
  AssetsAudioPlayer player = AssetsAudioPlayer.withId('saylo_player');

  static final Map<String, Player> _cache = {};

  Player._createInstance();

  factory Player() {
    if (!_cache.containsKey("player")) {
      Player instance = Player._createInstance();
      _cache["player"] = instance;
      instance.player.onErrorDo = (handler) {
        handler.player.stop();
      };
    }
    return _cache['player'];
  }
}

AssetsAudioPlayer player = Player().player;

Inside Provider...

player.open(
      Playlist(
        audios: songs
            .map<Audio>(
              (song) => Audio.network(
                song.songUrl,
                metas: Metas(
                  id: song.id,
                  title: song.name,
                  artist: song.artist ?? "artist",
                  album: song.album ?? "album",
                  image: MetasImage.network(song.coverUrl),
                ),
              ),
            )
            .toList(),
      ),
      showNotification: true,
      autoStart: false,
);
player.play();

Also it plays twice sometimes. And can't stop without closing app.

Looks good to me, however you might wanna use auto start insead of manually calling play.

Didn't work either.

markst commented 3 years ago
player.open(
      Playlist(
        audios: songs
            .map<Audio>(
              (song) => Audio.network(

@Kashish-Manandhar are you using Audio.network? if you're playing audio from assets folder like you mention - you might want to try Audio.file

Kashish-Manandhar commented 3 years ago

ok i will try to use it

nimr77 commented 2 years ago

It feels like the player is starting to download and write the file and then start to play