Page 1 of 1

Very Simple MP3 Player DLL

Posted: Sun May 12, 2013 12:23 am
by StevenM
PlayMPEG32.DLL loads and plays an mp3.

Download here:
http://www.freewebz.com/lb-connection/lb3.htm

The dll was created by Brad Moore and made for liberty basic, but works with ZGE as well.

Though it is limited - it's very easy to use with one function:


ExternalLibrary Stdcall:

Code: Select all

int PlayMPEG (string Filename){}
OnLoaded :

Code: Select all

string f="AnyMP3File.mp3";
PlayMPEG(f);

More importantly - it runs in a background thread.
License Details are included in the zip file.


Note: There is no need to NULL terminate strings in ZGE.

I did not test file paths with spaces yet. If you have an issue.
try putting the filename in quotes.

"\""+File+"\"" or
chr(34)+File+ chr(34)

Posted: Sun May 12, 2013 2:00 am
by Kjell
Hi Steven,

You don't need a ( additional ) DLL to play mp3 files though .. simply use the standard playback features of your OS. Try this super-simple example for Windows :wink:

K

Posted: Sun May 12, 2013 4:21 am
by StevenM
Wow, it is easy. All the examples I found were using filename+" type mpegvideo alias..." and a 0 for "null". I couldn't get it to work in zge.

Re:

Posted: Mon Feb 12, 2018 9:34 pm
by ultimatejew
Kjell wrote:Hi Steven,

You don't need a ( additional ) DLL to play mp3 files though .. simply use the standard playback features of your OS. Try this super-simple example for Windows :wink:
Could I have this reuploaded or re- explained?

Re: Very Simple MP3 Player DLL

Posted: Tue Feb 13, 2018 11:25 am
by Kjell
Hi,

The file is still there .. but Dropbox changed the way public files / links work in 2017. Anyway, here the new link :)

K

Re: Very Simple MP3 Player DLL

Posted: Wed Feb 14, 2018 12:10 am
by ultimatejew
Kjell wrote:Hi,

The file is still there .. but Dropbox changed the way public files / links work in 2017. Anyway, here the new link :)

K

Thank you very much <3

Re: Very Simple MP3 Player DLL

Posted: Fri Sep 13, 2019 4:28 am
by rrTea
Is there any way to control the volume? I'm trying to fade a song at a particular point at the end of the stage.

I've been looking here:
https://docs.microsoft.com/en-us/window ... nd-strings
but don't see any commands that would do that.

Re: Very Simple MP3 Player DLL

Posted: Fri Sep 13, 2019 9:55 am
by Kjell
Hi rrTea,
rrTea wrote: Fri Sep 13, 2019 4:28 amIs there any way to control the volume? I'm trying to fade a song at a particular point at the end of the stage.
Sure, put the following ZExpression in App.OnUpdate of the Sunset example for a demonstration ( move mouse up & down to control the volume ).

Code: Select all

float v = (App.MousePosition.Y+1)*500;
mciSendStringA("setaudio Sunset.mp3 volume to "+intToStr(v), null, 0, 0);
K

Re: Very Simple MP3 Player DLL

Posted: Fri Sep 13, 2019 10:18 am
by rrTea
Aah so that's how it's done. Great, it works! Thank you!

Re: Very Simple MP3 Player DLL

Posted: Sat Sep 14, 2019 6:34 am
by rrTea
Do I always have to refer to a particular file name in order to stop it or is there a way to just issue a command "Stop current playing track"?

I'm asking because the game can be quit at any moment and upon quitting the game I have to stop whatever tune is playing (if any!) in OnLeave. Right now I don't store names of the songs once I start playing them but I can put them in some variable or such if needed.

Re: Very Simple MP3 Player DLL

Posted: Sat Sep 14, 2019 10:10 am
by Kjell
rrTea wrote: Sat Sep 14, 2019 6:34 amDo I always have to refer to a particular file name in order to stop it or is there a way to just issue a command "Stop current playing track"?
You can assign a alias ... which requires the file to be opened & closed ( instead of just play & stop ). It's pretty straight-forward though, here's a modified Sunset.zgeproj example.

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExternalLibrary ModuleName="Winmm.dll">
      <Source>
<![CDATA[//

int mciSendStringA(string lpszCommand, xptr lpszReturnString, int cchReturn, int hwndCallback){}]]>
      </Source>
    </ZExternalLibrary>
    <ZExpression>
      <Expression>
<![CDATA[//

mciSendStringA("open Sunset.mp3 alias BGM", null, 0, 0);
mciSendStringA("play BGM", null, 0, 0);]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <OnUpdate>
    <KeyPress Keys="{" RepeatDelay="0.5">
      <OnPressed>
        <ZExpression>
          <Expression>
<![CDATA[//

if(Pause)
{
  mciSendStringA("play BGM", null, 0, 0);
}
else
{
  mciSendStringA("stop BGM", null, 0, 0);
}

//

Pause = !Pause;]]>
          </Expression>
        </ZExpression>
      </OnPressed>
    </KeyPress>
  </OnUpdate>
  <OnClose>
    <ZExpression>
      <Expression>
<![CDATA[//

mciSendStringA("close BGM", null, 0, 0);]]>
      </Expression>
    </ZExpression>
  </OnClose>
  <Content>
    <Variable Name="Pause" Type="4"/>
  </Content>
</ZApplication>
Press left-mouse-button to pause & resume the track ( this is just to illustrate how the play & stop commands work in this situation ).

K

Re: Very Simple MP3 Player DLL

Posted: Sat Sep 14, 2019 10:16 am
by rrTea
Excellent, yes that is pretty straightforward. Thanks!