开发者

Output sound through speaker when not logged in

I have a program written in Delphi XE that plays a WAV file using TMediaPlayer. The program runs in the system tray on a Windows 7 computer. The program waits for an event to trigger playing the wav file. If I am logged in on the computer itself, the wav plays fine. But if I lock the computer terminal (or log in through Remote Desktop), the wav file does not play through the computer speaker. I know the event is being triggered because all the other code in the event handler works just fine; it's just that you can't hear the wav file. I have hard-coded the volum开发者_StackOverflow中文版e to the maximum level so I know it's not a volume problem. Does Windows 7 have something that prevents sounds coming through the speaker if no one is currently logged in to the computer? If that limitation exists, is there a way around it?


As Brad suggests, use PlaySound() instead of TMediaPlayer. It works fine when the the machine is 'locked'. Not sure about it working over a remote desktop connection though.

To confirm this, I created a new app, put a TTimer on the form, set the Interval property to 20000 and put this code in the OnTimer event:

procedure TForm13.Timer1Timer(Sender: TObject);
begin
  PlaySound('c:\windows\media\tada.wav', 0, SND_ASYNC or SND_FILENAME);
end;

Then I ran it, locked the console (with Windows L), and waited 20 seconds. The sound played successfully.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜