Very Simple MP3 Player DLL

Use of external libraries (DLLs) from ZGE.

Moderator: Moderators

Post Reply
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Very Simple MP3 Player DLL

Post 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)
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Post 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.
ultimatejew
Posts: 2
Joined: Mon Feb 12, 2018 9:33 pm

Re:

Post 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?
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Re: Very Simple MP3 Player DLL

Post 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
ultimatejew
Posts: 2
Joined: Mon Feb 12, 2018 9:33 pm

Re: Very Simple MP3 Player DLL

Post 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
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Very Simple MP3 Player DLL

Post 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.
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Re: Very Simple MP3 Player DLL

Post 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
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Very Simple MP3 Player DLL

Post by rrTea »

Aah so that's how it's done. Great, it works! Thank you!
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Very Simple MP3 Player DLL

Post 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.
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Re: Very Simple MP3 Player DLL

Post 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
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Very Simple MP3 Player DLL

Post by rrTea »

Excellent, yes that is pretty straightforward. Thanks!
Post Reply