I need to write program that will be given some path as a parameter, and play audiofile, located in that path. But after i call that program second time-i need first one to finish playing file and after that-play second file, that was passed as a parameter to second instance. How to pass second parameter as queue to first program instance if its possible..?
2 Answers
I guess you're describing the following strategy:-
- instance A of your app is open and playing track X.
- the user double clicks track Y in explorer
- windows starts instance B of your app, passing in the filename as a parameter
- instance B detects instance A
- instance B sends a message to instance A to play track Y
- instance B shuts down
- instance A receives the message, stops playing track X and starts playing track Y
Evidently this is the way VLC media player works. If you try the above, you will see a new VLC process appear for a short time before your current instance starts playing the new track.
This kind of very simple cross process communication can be achieved using something like System.Threading.Mutex. E.g. you could use one mutex to indicate the existence of a currently running instance and another for passing the new track name to the current instance.
In fact, this article describes something quite similar.
2 Comments
I don't think you need second instance of program for this purpose. You can simply ask the first program to play the new audio file once it has finished playing the first. You can achieve this via several ways.
You can host a WCF Service inside your program which plays the audio file. It will be playing audio and will be listening to WCF Service in parallel. Program that sends the second parameter will pass the new path via WCF Service.
Similarly you can use sockets for communication
A third way could be to use Windows Message Queues. Audio player will be continuously pooling the queue for the new paths. The second program will send the new file path via adding a message in Windows Message Queue
You can also use files for communication. Audio player can look for changes in file and other program can write paths to that file