Open UdithaIshan opened 3 years ago
Hi @UdithaIshan !
Not the best solution, but you may use getDuration
from the AudioPlayer class & Timer
from dart:async
to detect when a track ends & start playing another audio that time.
This library is a very minimal implementation over miniaudio, even streams aren't added yet. You are supposed to make your own playback logic in dart.
Thankyou.
@alexmercerind I also thought about that, but then we can't use the pause method
on it.
And I appreciate your work on implementing this.
Cheers 🍻
@UdithaIshan, ah I see.
I'll try to do something regarding this in future.
Hi there @UdithaIshan!
I know I'm very late to reply on this. 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.
Thanks
The stream has way to much stuff going through it, in the example try slowly dragging the slider to forward the song, its going to take a VERY long time for eventloop to catch up. If you just click anywhere on slider that would obviously work.
@syleishere
Its not because of stream being bloated, its because its just a Stream.periodic
with refresh duration of 100ms.
And, delay is caused by miniaudio. As one is not supposed to not change position every millisecond one drags, I haven't implemented any such condition to just ignore too many subsequent calls. So, just click on the slider somewhere for now.
So I ran song looping for over 24 hours on my windows machine without any issues. I found the error seems to be IsCompleted gets set before it should, requiring a call back to eventloop so whatever needs finishing finishes before another song can be started, so I found just tossing another song back in eventloop to start with even a 1 millisecond duration will allow one song to be played after the other with no issues:
Example that has worked for me:
class FirstPage2 extends State { String text0 = "Now Playing: \nOld Song 1"; String text1 = "Old Song 1"; String text2 = 'Old Song 2'; AudioPlayer desktopPlayer; @override void initState() { super.initState(); 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}"); //var mysleep = const Duration(hours: 0, minutes: 0, seconds: 1); //We just need to toss starting a new song back into eventloop as something is wrong with IsCompleted and still needs to finish something Timer(Duration(milliseconds: 1), () { audioStart(); }); //audioStart().then((response){ //hack to execute an async function in a non-async function // print("Executing async function in non-async function"); //}); //setState(() { //THIS WILL FUCKUP use provider instead // text0 = 'Sexy Baby we playing a song!'; // text1 = 'Love me sexy baby'; //}); } }, ); } }
I guess my only suggestion at this point would be if you are going to do a queuing system for songs, to play the songs in a separate isolate so that GUI is not affected for anything other than communicating with the isolate to play a song. Also so it can utilize another core on the CPU for playing songs :)
I think would be a good idea to do an implementation in pure dart, would keep code clean and maintainable, then on flutter side just show people how to communicate with the isolate :)
Hi there @UdithaIshan ! I hope you are doing great.
Thanks for supporting this project. Now libVLC based alternative to this project is live: dart_vlc
It has (in addition to this project):
Other features are in the list. Please use that plugin now instead of this one.
Hope you liked my work. I'm in collaboration with just_audio & assets_audio_player to make Flutter on Windows & Linux a more better place.
How can I play multiple songs one after another using this? @alexmercerind