elibroftw / music-caster

Music Caster is a modern music player with the ability to cast audio files, system audio, and URLs to Google Chromecasts, Google Home/Nest Minis, etc.
https://elijahlopez.ca/music-caster/
Other
142 stars 16 forks source link

[Bug] Multiple Instances if many Runs #43

Closed tomhammond closed 2 years ago

tomhammond commented 2 years ago

Hi Elijah,

Would you consider adding a feature to Music Caster so that it only allows one instance at startup? That is, to prevent multiple copies of the program from running at the same time.

The situation is this: When I tell Google Home to start playing music, there are multiple speakers in my house listening for commands. Sometimes those multiple speakers trigger the command simultaneously to Music Caster at the same time.

When this happens, there are multiple, identical streams being sent to the smart speakers, causing playback to be choppy on some speakers, even causing them to temporarily break connection to wifi.

If Music Caster can avoid starting if it detects itself already running, that would help. The trick is, Google Home fires the commands to start multiple instances of MC in rapid succession, so the first instance may not be fully loaded before the second instance attempts to start. Perhaps add a feature so that MC creates a registry key as the first very thing it does at startup to indicate that it is starting, then other instances can check for they key when they attempt to start.

Thanks so much for your help. Music Caster is truly wonderful; I use it every day for my house music!

Take care, Tom Hammond

elibroftw commented 2 years ago

I did have pid files to detect multiple instances and had extra guards against it but I'll take a look again. The thing is I optimized the program so much that multiple instances can't read the pis values slow enough. Registry is a good idea so I'll use that.

tomhammond commented 2 years ago

Thanks for looking into this. I did a lot of troubleshooting; I know the problem is not with my router or wifi. If I close the office door so that only one speaker hears my command, Music Caster mostly works perfectly fine when I trigger it by voice command.

Maybe your pid files and other guards only work after the first instance has fully loaded? In my case, I think the first instance has partially loaded when the second instance tries to start up, creating a conflict. That's just a guess. :)

Thanks! Topm

On Tue, Feb 22, 2022 at 8:03 AM Elijah Lopez @.***> wrote:

I did have pid files to detect multiple instances and had extra guards against it but I'll take a look again.

— Reply to this email directly, view it on GitHub https://github.com/elibroftw/music-caster/issues/43#issuecomment-1047775368, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVBMB5W4G3AO4ZDTD2VNBTU4OCTNANCNFSM5PBKKWFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

elibroftw commented 2 years ago

What happens is that the other instances start so fast that they read the same pid file that the first instance read. My guards are placed after the port binding to make a request to the server. What I think I'll do is move the guards down until the command line paths would be played.

OH wait, I think they also bind to the same port sometimes so the port checking code can be incorrect at times as well. All around, many problems.

tomhammond commented 2 years ago

I noticed that when choppy music happens during casting (I assume it's from multiple instances of Music Caster trying to stream at the same time), closing Music Caster does not stop the streaming. There is still choppy playback on the speakers, at least until the current MP3 file finishes. Even rebooting the computer does not stop this playback. The smart speakers are in an unable state for a while, unable to recover to normal mode. Some even lose connection to wifi, which is strange. The problem isn't with the router; I replaced it with a stronger one.

My guess is that the speakers are receiving multiple, identical streams from multiple instances of Music Caster, which confuses the speakers and causes the choppy playback. Also note that I am casting to a speaker group.

Casting and voice control work fine when I am giving the commands to one speaker (and I ensure they others are not listening). That's why I think it is a problem with multiple instances of streaming. It's my best guess.

Thanks, Tom

On Tue, Feb 22, 2022 at 8:03 AM Elijah Lopez @.***> wrote:

I did have pid files to detect multiple instances and had extra guards against it but I'll take a look again.

— Reply to this email directly, view it on GitHub https://github.com/elibroftw/music-caster/issues/43#issuecomment-1047775368, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVBMB5W4G3AO4ZDTD2VNBTU4OCTNANCNFSM5PBKKWFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

elibroftw commented 2 years ago

It's choppy because Music Caster has a server which isn't production. It is my fault partly, I just haven't bothered switching it to something for production because there wasn't a use case to need multiple connections. Are you exiting the program using the keyboard binding or the tray? Both should stop playback for their respective chromecasts.

tomhammond commented 2 years ago

Sounds good. I am happy to help with troubleshooting that you want me to try on this end. :)

On Tue, Feb 22, 2022 at 8:29 AM Elijah Lopez @.***> wrote:

What happens is that the other instances start so fast that they read the same pid file that the first instance read. My guards are placed after the port binding to make a request to the server. What I think I'll do is move the guards down until the command line paths would be played.

— Reply to this email directly, view it on GitHub https://github.com/elibroftw/music-caster/issues/43#issuecomment-1047798272, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVBMB6T4Z57CG2NFIJ7MLDU4OFUHANCNFSM5PBKKWFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

tomhammond commented 2 years ago

If I remember correctly, I think I am using the command line argument --exit to exit the program. I have also tried exiting via the tray. Both seem unable to halt playback while the choppy audio problem is happening.

As an aside, is there a keyboard shortcut for advancing to the next song in a queue?

Thanks, Tom

On Tue, Feb 22, 2022 at 8:51 AM Elijah Lopez @.***> wrote:

It's choppy because Music Caster has a server which isn't production. It is my fault partly, I just haven't bothered switching it to something for production because there wasn't a use case to need multiple connections. Are you exiting the program using the keyboard binding or the tray? Both should stop playback for their respective chromecasts.

— Reply to this email directly, view it on GitHub https://github.com/elibroftw/music-caster/issues/43#issuecomment-1047817146, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVBMB5OQZ63M2PU4YVJGLLU4OIFNANCNFSM5PBKKWFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

elibroftw commented 2 years ago

The next track shortcut is the keyboard defined shortcut/button for it. There should be a symbol on your keyboard for it. I'll add the shortcut if your keyboard doesn't support it.

elibroftw commented 2 years ago

Also, I think your voice commands will screw up the player unless you are using a cast group. As it sounds you are telling the player to play the track on each of the cast devices. This will lead to a bunch of device switches and it'll play on the last device that sent the command. Is there no way to ensure there is only one command to process?

tomhammond commented 2 years ago

My keyboard doesn't have a next track button on it; could you add a shortcut for a regular key for skipping to next track? Thanks.

On Tue, Feb 22, 2022 at 1:54 PM Elijah Lopez @.***> wrote:

The next track shortcut is the keyboard defined shortcut/button for it. There should be a symbol on your keyboard for it. I'll add the shortcut if your keyboard doesn't support it.

— Reply to this email directly, view it on GitHub https://github.com/elibroftw/music-caster/issues/43#issuecomment-1048110598, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVBMB5HSAXJJTLUDL54O6LU4PLWXANCNFSM5PBKKWFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

tomhammond commented 2 years ago

I am using a cast group. Did you make changes to the multi-instance guard code? Is there an updated version of MC that you want me to try?

Thanks, Tom

On Tue, Feb 22, 2022 at 1:55 PM Elijah Lopez @.***> wrote:

Also, I think your voice commands will screw up the player unless you are using a cast group.

— Reply to this email directly, view it on GitHub https://github.com/elibroftw/music-caster/issues/43#issuecomment-1048111049, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVBMB3X5UD2URSM7WBOL43U4PLY5ANCNFSM5PBKKWFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

elibroftw commented 2 years ago

Yes try the latest one. I tested quick launches and only one instance was created

tomhammond commented 2 years ago

OK, I will try that version tonight. Thank you!

Tom

On Tue, Feb 22, 2022 at 2:34 PM Elijah Lopez @.***> wrote:

Yes try the latest one. I tested quick launches and only one instance was created

— Reply to this email directly, view it on GitHub https://github.com/elibroftw/music-caster/issues/43#issuecomment-1048142298, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVBMB4HYHFJBEIWSPEUMODU4PQLHANCNFSM5PBKKWFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

tomhammond commented 2 years ago

Hi Elijah,

Those improvements helped! I get no more multiple instances of Music Caster when I give voice commands and multiple smart speakers try to start it at once. It works beautifully now! I can play 12 different music collections with my voice with “hey google, turn on classical music” and such. And when I’m done listening, I can say “hey google, turn off classical music”. Very smooth!

If I send a donation via PayPal, where should I send it to?

Thanks so much for all of your help. Music Caster is awesome!

Tom

From: Elijah Lopez @.> Sent: Tuesday, February 22, 2022 2:34 PM To: elibroftw/music-caster @.> Cc: tomhammond @.>; Author @.> Subject: Re: [elibroftw/music-caster] [Bug] Multiple Instances if many Runs (Issue #43)

Yes try the latest one. I tested quick launches and only one instance was created

— Reply to this email directly, view it on GitHub https://github.com/elibroftw/music-caster/issues/43#issuecomment-1048142298 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVBMB4HYHFJBEIWSPEUMODU4PQLHANCNFSM5PBKKWFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AEVBMB6XFDMFJFET3FBNXVLU4PQLHA5CNFSM5PBKKWFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHZ4WDWQ.gif Message ID: @. @.> >

elibroftw commented 2 years ago

There's links to donate in the readme. You're welcome and thanks for the feedback as it forces me to improve the program.

tomhammond commented 2 years ago

OK, donation sent! 😊

From: Elijah Lopez @.> Sent: Tuesday, February 22, 2022 9:12 PM To: elibroftw/music-caster @.> Cc: tomhammond @.>; Author @.> Subject: Re: [elibroftw/music-caster] [Bug] Multiple Instances if many Runs (Issue #43)

There's links to donate in the readme. You're welcome and thanks for the feedback as it forces me to improve the program.

— Reply to this email directly, view it on GitHub https://github.com/elibroftw/music-caster/issues/43#issuecomment-1048389994 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AEVBMB6T3RA22ORRGXUJMKLU4Q7ARANCNFSM5PBKKWFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AEVBMB2HSU5VZ365K5GTIILU4Q7ARA5CNFSM5PBKKWFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHZ6SS2Q.gif Message ID: @. @.> >