Recent

Author Topic: Play MP3 file with MCISendString  (Read 3126 times)

badmintonfan

  • New Member
  • *
  • Posts: 47
Play MP3 file with MCISendString
« on: November 23, 2020, 05:59:31 am »
uses
  mmsystem;
procedure TForm1.Button1Click(Sender: TObject);
begin
MCISendString('OPEN e:\1.mp3 TYPE mpegvideo alias ww',nil, 0, 0);
MCISendString('PLAY WW', nil, 0, 0);
MCISendString('CLOSE ANIMATION', nil, 0, 0);
end;
I write the above code to play mp3,it works but the file name is Chinese character, is there any way to fix it

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Play MP3 file with MCISendString
« Reply #1 on: November 23, 2020, 10:32:39 am »
Use the "wide" variant of MCISendString, and pass the arguments as UnicodeString. This works for me:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   MCISendStringW(PWideChar(UTF8Decode('OPEN äöü.mp3 TYPE mpegvideo alias ww')), nil, 0, 0);
  4.   MCISendString('PLAY WW', nil, 0, 0);
  5.   MCISendString('CLOSE ANIMATION', nil, 0, 0);
  6. end;

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Play MP3 file with MCISendString
« Reply #2 on: November 23, 2020, 01:32:17 pm »
hello,
good job, wp
here is an enhanced code to  show what is wrong when the command open doesn't work  :
Code: Pascal  [Select][+][-]
  1. // uses mmsystem, LConvEncoding;
  2. procedure TForm1.Button7Click(Sender: TObject);
  3. const
  4.   ErrorMessageBufSize = 128;
  5. Var
  6. ReturnCode : MCIERROR;
  7. ErrorMessage : String;
  8. Command : String;
  9. begin
  10. SetLength(ErrorMessage,ErrorMessageBufSize);
  11. // Close the sounds if already used
  12. MCISendString('close ww',nil,0,0);
  13. Command := 'OPEN "M:\zic\C''est déjà ça.mp3"' + ' TYPE mpegvideo alias ww'; // A.Souchon song
  14. ReturnCode := MCISendStringW(PWideChar(UTF8Decode(Command)),nil, 0, 0);
  15. if ReturnCode <> 0 then
  16.   begin
  17.       MCIGetErrorString(ReturnCode,@ErrorMessage[1],ErrorMessageBufSize);
  18.       ErrorMessage := Copy(ErrorMessage,1,Pos(#0,ErrorMessage) - 1);
  19.       ShowMessage(CP1252ToUTF8(ErrorMessage));    // latin1
  20.   end;
  21. MCISendString('PLAY ww', nil, 0, 0);
  22. MCISendString('CLOSE ANIMATION', nil, 0, 0);
  23. end;

Friendly, J.P
« Last Edit: November 23, 2020, 01:34:25 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

badmintonfan

  • New Member
  • *
  • Posts: 47
Re: Play MP3 file with MCISendString
« Reply #3 on: November 24, 2020, 04:16:48 am »
Thanks all,here is the another issue when I use pwidechar
In compatible type for arg no. 1:Got "Pwidechar",expected "Pchar"

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Play MP3 file with MCISendString
« Reply #4 on: November 24, 2020, 09:27:05 am »
Did you notice the appended "W" in the MCISendString call?

badmintonfan

  • New Member
  • *
  • Posts: 47
Re: Play MP3 file with MCISendString
« Reply #5 on: November 25, 2020, 02:57:54 am »
Thanks, it works!

 

TinyPortal © 2005-2018