Can I play an mp3 sound file on Windows without relying on a dll? lazarus / 34-Windows ---------------------------------------------------------------------- EganSolo · 2023-05-04 05:24 Not sure if I should ask this question in the Windows subforum or the multimedia one ... Anyway, like the subject says: could I play an mp3 sound file without loading a DLL on Windows 10 and 11? ---------------------------------------------------------------------- TRon · 2023-05-04 05:34 Nope. Or actually yes, but in that case you will not have any sound output. ---------------------------------------------------------------------- Jurassic Pork · 2023-05-04 06:17 Hello, on Windows you can try to use the windows media player COM object : Example : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  Form1: TForm1;  OWMP: OleVariant;implementation uses ComObj;{$R *.lfm}{ TForm1 }procedure TForm1.FormCreate(Sender: TObject);begin   OWMP := CreateOleObject('WMPlayer.OCX.7');end;procedure TForm1.BtPlayClick(Sender: TObject);begin   OWMP.Url := 'D:\Zic\Merci Patron.mp3';end;procedure TForm1.BtStopClick(Sender: TObject);begin  OWMP.Controls.Stop;end;  Friendly, J.P ---------------------------------------------------------------------- TRon · 2023-05-04 06:27 @Jurassic Pork: Still loading DLL's there (whether it be directly or indirectly) ---------------------------------------------------------------------- Jurassic Pork · 2023-05-04 06:29 Quote from: TRon on May 04, 2023, 08:27:20 am@Jurassic Pork: Still loading DLL's there (whether it be directly or indirectly)  but invisible and no dll install necessary ---------------------------------------------------------------------- TRon · 2023-05-04 06:36 Quote from: Jurassic Pork on May 04, 2023, 08:29:38 ambut invisible and no dll install necessary  True but, not what was asked for (though I do not know the intention of TS with the phrase "without loading a dll"). I would personally prefer to use mmsystem for playing sound (but that's just me). ---------------------------------------------------------------------- Thaddy · 2023-05-04 08:31 Yes, you can, since a native MP3 in Pascal is available for years. (About 20, mine in 2003 for Delphi, based on German Magazine code and I did just KOL) I translated it to KOL, but I can also translate it back. (Since the original disappeared because of then current rights, nowadays there are no restrictions) BUT: under Windows you will always rely on some dll's from Windows audio drivers as explained above, but that is basically the OS. Note that my code is basically only of interest to explain how MP3 is encoded/decoded. I would not recommend it since Windows supports mp3 natively. It may be of interest for cross-platform. My code also contains a small bug, since the encoding uses signed integer, so 1 bit is lost.(Usually not audible) Ping me if you want that code. Note it is very complex so if you are not a very, very capable programmer it would be useless to you. The code only compiles in $mode delphi, but it works. I will have a look on some old disks if you can not google it. (20 years ago is a long time) ---------------------------------------------------------------------- BobDog · 2023-05-04 10:04 With Windows you have a built in video/audio player. For audio, with your own path to a file: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   function mciSendString(s: pchar; p1: pchar; p2: integer; p3: integer): integer;  cdecl external 'Winmm.dll' Name 'mciSendStringA'; function playaudio(filename:ansistring):integer;varopen:ansistring;beginOpen := 'open  ' + filename + ' type mpegvideo alias file1';mciSendString(pchar(open), Nil, 0, 0); exit(mciSendString('play file1', nil, 0,0));end;  beginwriteln(playaudio('C:\Users\Computer\Lea vingOnAJetPlane.mp3'));readln;end. Oops ..., just realized that I use a dll, albeit a built in one. Do you mean write a decoder from first principles? ---------------------------------------------------------------------- EganSolo · 2023-05-04 18:37 Thanks, everyone for your thorough and detailed answer. As @Tron pointed out, I was looking for a solution that would be pure Pascal. We have solutions to load images that do not require any DLL so I thought (perhaps naively) that the same could be achieved without sound. @Jurassic Pork: To your point, relying on a native DLL is, in my mind, better than loading a library, so thank you for your code. The same goes for @Bobdog for the code. Yes, both of these snippets rely on native DLLs but it may be better than loading a different library. @Thaddy: Is there even a sliver of a chance that your code could be turned into a pure Pascal mp3 player component? I thought I should ask! ---------------------------------------------------------------------- TRon · 2023-05-04 18:49 @EganSolo: Decoding MP3, turning it into waveforms all that can be done 'natively' in Pascal. The part that definitely can not be done in Pascal without relying on some OS functionality (on Windows that does mean relying on a dll) is outputting that waveform so that it actually generates sound that you can listen to. No problem storing the waveforms f.e. to a wav file. edit Since you asked (and for Windows only) , perhaps try https://sourceforge.net/projects/delphimpeg/ ?