The OP said “ it plays the file after some nano seconds ” so my assumption is that the latency that he is concerned about is quite short (not hundreds of milliseconds) and could be a result of using SDL_mixer.
Fair enough, I had that wrong number in my mind because of the SDL_Delay() up there in the OP’s code. My bad. Then again, I very much doubt a delay of “some nanoseconds” would be measurable, let alone avoidable.
More easily, open the device with the format of the file (if it’s a format the device is capable of). The only way to keep latency as low as possible is to avoid any ‘real time’ format conversion.
Sure, if you know your runtime environment and can control the format of the file, this is a good solution. And avoids a dependency. I suggested SDL_mixer because it is a nice, well-rounded solution that satisfies the needs of most people. If the latency provided by SDL_mixer is not good enough for something, it is usually a very specialized thing. Which brings us to the following:
The real issue I am having with this thread is that the OP does not seem to know what needs to be accomplished, and does not paint a good picture for us to arrive at a good solution. So, @cadsys, what is it that your application does? What is it? Why does it need to play the sound? What is the framework or library you re using to create the interface? First you said button, afterwards you said key. So it is a keyboard key, then? Is it all done with SDL? Without you better explaining what you want to accomplish, and why, advice based on speculation can only go so far.
Please, help us help you