Play Sound file without importing winmm.dll or microsoft.visualbasic.dll
I am writing a program using Delphi prism. The goal is to be able run on windows and linux (mono) from the same project. So, at this point I need to have a way of playing a sound file for windows and linux(mono) without having to import winmm.dll or microsoft.visualbasic.dll.
Since I need this to work on mono also, I don't want to use visualbasic.dll. In the past, it gave me all kinds of issues.
Are there ways to play sound file without using these dll files?
UPDATE
No matter how the soundplayer is instantiated and used, it always works fine under windows OS, whereas on Linux under mono it sometimes plays and other times it just won't play at all.
First Version:
var thesound := new SoundPlayer;
if Environment.OSVersion.Platform = Environment.OSVersio开发者_开发问答n.Platform.Unix then
thesound.SoundLocation := '/sounds/Alarms.wav'
else
thesound.SoundLocation:='\sounds\Alarms.wav';
thesound.Load;
thesound.PlayLooping;
Second Version
var sp := new SoundPlayer(new FileStream("/sounds/Alarms.wav", FileMode.Open, FileAccess.Read, FileShare.Read));
sp.PlayLooping;
You can use System.Media.SoundPlayer
. This is implemented by Mono.
精彩评论