alexmercerind / flutter_audio_desktop

[WIP] An 🎵 audio playback library for Flutter Desktop. Supports Windows & Linux. Based on miniaudio.
MIT License
53 stars 18 forks source link

Repeat sound #26

Closed Elblassy closed 3 years ago

Elblassy commented 3 years ago

I try to repeat sound by listen when sound end and play it again but it can't , so how can i repeat sound

Elblassy commented 3 years ago

I see that you type a comment in stop i should load file again and i do that and it work , thank you for your effort in this plugin

Elblassy commented 3 years ago

I face issue when call play sound in listen of stream the app crash and don't get any error, all i want to do is to repeat sound , any help please

Elblassy commented 3 years ago

i solve it by timer and provider , but i wish you can add function for repeat without load file again

Elblassy commented 3 years ago

sometimes get same error and lost connection without any debug message

Elblassy commented 3 years ago

I solve it by making the object of audioplayer in singleton and access it with it , i don't know why it working only when i use singleton for the object

alexmercerind commented 3 years ago

Hi there @Elblassy !

I know I'm very late to reply on this, apologies.

But this issue is under progress in the vnext now.

Now, one can listen to playback events, which will help me add things like playlists, looping etc. Windows implementation coming real soon.

Issue #25 is exactly same as this issue. So, let's target this issue there.

Greetings 🍀

syleishere commented 3 years ago

HOw did you pull it off with timer and provider? I have a weird situation as follows below where I can't seem to get it to play after song stops, yet it i click Play on player it works again calling same code? Strange it almost seems like it needs a pause of a second or 2, I'll keep trying...

if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
  desktopPlayer = new AudioPlayer(id: 0);
  print("Initializing Music Player, Stats are completed: ${desktopPlayer.audio.isCompleted} stopped: ${desktopPlayer.audio.isStopped}");
  desktopPlayer.stream.listen(
    (Audio audio) {
      if (desktopPlayer.audio.isCompleted) {
        print("Song finished playing, Stats are completed: ${desktopPlayer.audio.isCompleted} stopped: ${desktopPlayer.audio.isStopped}");
        //audioStop();
        audioStart();
        //setState(() {   //THIS WILL FUCKUP use provider instead
        //  text0 = 'Sexy Baby we playing a song!';
        //  text1 = 'Love me sexy baby';
        //});
      }
    },
  );
}
syleishere commented 3 years ago

Just for reference this is audioStart:

audioStart() async { print("Do we make it here 4?"); String mp3 = 'Z:/mp3/newday.mp3'; print("Entering play function, Stats are completed: ${desktopPlayer.audio.isCompleted} stopped: ${desktopPlayer.audio.isStopped}"); if (desktopPlayer.audio.isStopped || desktopPlayer.audio.isCompleted) { await desktopPlayer.load(AudioSource.fromFile(new File(mp3))).catchError((onError) { print("Error occured what happened is: ${onError}"); }); print("Playing Song: ${mp3} Position: ${await desktopPlayer.position}"); print("ABOUT TO START FUCKING SONG WHY NOT WORKING?, Stats are completed: ${desktopPlayer.audio.isCompleted} stopped: ${desktopPlayer.audio.isStopped}");

  await desktopPlayer.play(); //when a song finishes, isPlaying still returns true, so catch it here
  return;
}
print("Better not make it here, Stats are completed: ${desktopPlayer.audio.isCompleted} stopped: ${desktopPlayer.audio.isStopped}");

if (desktopPlayer.audio.isPlaying) {
  print("Pausing Song: ${mp3} Position: ${await desktopPlayer.position}");
  await desktopPlayer.pause();
} else {
  print("Playing Song: ${mp3} Position: ${await desktopPlayer.position}");
  await desktopPlayer.play();
}

}

syleishere commented 3 years ago

I got it to work, it needs a timeout for whatever reason after it returns completed, I changed audioStart to: Timer(Duration(seconds:1),(){ print("awake going to start SONG NOW!!!"); audioStart(); });

and everything works now, not sure why....

alexmercerind commented 3 years ago

@syleishere ,

miniaudio itself has default behaviour of repeating the sound. It is actually intentionally removed by me, so that I can get a bit more control over the playback & stream. I'll add whole separate Queue class for dealing with repeat, playlist etc. It will be all Dart side code.

I'm not familiar with advanced Dart like rx etc. So, that's also might be bit of problem in how things are right now.

alexmercerind commented 3 years ago

I can't seem to get it to play after song stops.

You are supposed to class load again, once the audio completes (then, play would work). You can listen to isCompleted event for that.

Currently ,everything is just shown to be functional & working to use. I'm not sure about any behaviour etc., I might change if people say.

alexmercerind commented 3 years ago

A side note after seeing your code.

audioPlayer.stop is more like "unload".

@syleishere... This whole issue is being taken care of at #25.

syleishere commented 3 years ago

Oww ok good to know, I was just checking status of isCompleted on stream so I could detect when song finishes so I could continue playing next song I was thinking for a playlist. My goal here is just to select a folder and have it play every song in it for time being, what is ETA on your queue system you figure if your going to implement that?

alexmercerind commented 3 years ago

what is ETA on your queue system you figure if your going to implement that?

I don't really spend too much of my time on this plugin, I have other projects I am more interested in. I'm not building any profit by doing this.

This plugin is literally one of the first plugins ever made for Windows or Linux (others are from Flutter team itself), so it takes time to figure it all up.

alexmercerind commented 3 years ago

@syleishere

You can ping me on Discord at alexmercerind#3898, I'm not really having fun in issue threads.