Destruktion
Programmer
Hi, a question for you experts. I have asked in other places but get not answers, this forum seems to be much more helpful so hopefully I can get some help and advice here
I have a hobby program Im making (a basic music mixer type program) that allows to add tree nodes at runtime and load a WAV file, the WAV file is saved to a TStream via the Data pointer of the node. I can then play my WAV sound by finding the sound in my stream and assigning it to a temp TMemoryStream, i can then play it, here is an extract:
This works good, I am also saving my stream to file so it can be read at any other time from my app.
Now the question, I want to be able to play other media types as WAV is not as common as say MP3. I would like to play Midi sequences, MP3 and as a bonus other formats, but mainly Midi and MP3.
Now I know I could simply read the stream and save the file to disk, play the file and delete after, but if I can do this directly from a Memory stream it would be much faster and better.
So, How to play MP3 and Midi from TMemoryStream?
Thanks!
I have a hobby program Im making (a basic music mixer type program) that allows to add tree nodes at runtime and load a WAV file, the WAV file is saved to a TStream via the Data pointer of the node. I can then play my WAV sound by finding the sound in my stream and assigning it to a temp TMemoryStream, i can then play it, here is an extract:
Code:
procedure TfrmMain.actPlayExecute(Sender: TObject);
var
Data: TSoundData;
MemStream: TMemoryStream;
begin
Data:= TSoundData(tvwMain.Selected);
if Data <> nil then
begin
MemStream:= TMemoryStream.Create;
try
Data.Stream.Seek(0, soBeginning);
Data.Stream.CopyFrom(MemStream, MemStream.Size);
MemStream.LoadFromStream(Data.Stream);
sndPlaySound(MemStream.Memory, SND_MEMORY or SND_ASYNC);
MemStream.Free;
except on exception do
MemStream.Free;
end;
end;
end;
This works good, I am also saving my stream to file so it can be read at any other time from my app.
Now the question, I want to be able to play other media types as WAV is not as common as say MP3. I would like to play Midi sequences, MP3 and as a bonus other formats, but mainly Midi and MP3.
Now I know I could simply read the stream and save the file to disk, play the file and delete after, but if I can do this directly from a Memory stream it would be much faster and better.
So, How to play MP3 and Midi from TMemoryStream?
Thanks!