Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

Repeat sound #26

Closed
Elblassy opened this issue Jan 7, 2021 · 15 comments
Closed

Repeat sound #26

Elblassy opened this issue Jan 7, 2021 · 15 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@Elblassy
Copy link

Elblassy commented Jan 7, 2021

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
Copy link
Author

Elblassy commented Jan 7, 2021

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 Elblassy closed this as completed Jan 7, 2021
@Elblassy Elblassy reopened this Jan 8, 2021
@Elblassy
Copy link
Author

Elblassy commented Jan 8, 2021

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
Copy link
Author

Elblassy commented Jan 8, 2021

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

@Elblassy
Copy link
Author

Elblassy commented Jan 8, 2021

sometimes get same error and lost connection without any debug message

@alexmercerind alexmercerind added the enhancement New feature or request label Jan 8, 2021
@Elblassy
Copy link
Author

Elblassy commented Jan 8, 2021

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
Copy link
Owner

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 🍀

@alexmercerind alexmercerind added the duplicate This issue or pull request already exists label Feb 27, 2021
@syleishere
Copy link

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
Copy link

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
Copy link

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
Copy link
Owner

alexmercerind commented Mar 6, 2021

@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
Copy link
Owner

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
Copy link
Owner

alexmercerind commented Mar 6, 2021

A side note after seeing your code.

  • isCompleted is only true when the file ends (not when the player is stopped). Once, it gets true, it stays for few ms, then audioPlayer.stop is called internally.
  • isStopped indicates whether the file is loaded or not & has nothing to do with position or completion.

audioPlayer.stop is more like "unload".

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

@syleishere
Copy link

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
Copy link
Owner

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
Copy link
Owner

@syleishere

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants