Adding Mp3 To EO2.3

Thanks Damian666 for the other tutorial

I added this tutorial because the most didnt found the things e.c.t.

First download: modDxShow.bas and add it to your Project

(modDxShow.bas -> client src)

(Project -> Add module -> Existing -> Src -> modDxShow.bas)

Now go to Project>references and add a ref to active movie control type library.

modGeneral search

 ' Cache music list

strLoad = Dir(App.Path & MUSIC_PATH & "*.mid")

i = 1

Do While strLoad > vbNullString

ReDim Preserve musicCache(1 To i) As String

musicCache(i) = strLoad

strLoad = Dir

i = i + 1

Loop

Add under it

 'Cache MP3

strLoad = Dir(App.Path & MUSIC_PATH & "*.mp3")

i = 1

Do While strLoad > vbNullString

ReDim Preserve musicCache(1 To i) As String

musicCache(i) = strLoad

strLoad = Dir

i = i + 1

Loop

modGameLogic search

 ' Calculate fps

If TickFPS < Tick Then

GameFPS = FPS

TickFPS = Tick + 1000

FPS = 0

Else

FPS = FPS + 1

End If

add under it

 'loop mapmusic if needed and its a mp3 file

LoopMp3

modSound search

Public Sub PlayMidi

and replace with

Public Sub PlayMidi(ByVal Filename As String)

Dim Splitmusic() As String

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

If Options.Music = 0 Then Exit Sub

Splitmusic = Split(Filename, ".", , vbTextCompare)

If Performance Is Nothing Then Exit Sub

If LenB(Trim$(Filename)) < 1 Then Exit Sub

If UBound(Splitmusic) <> 1 Then Exit Sub

If Not FileExist(App.Path & MUSIC_PATH & Filename, True) Then Exit Sub

If Not Music_On Then Exit Sub

If Music_Playing = Filename Then Exit Sub

If Splitmusic(1) = "mp3" Then

OpenDShowFile (App.Path & MUSIC_PATH & Filename)

PlayMp3

Exit Sub

ElseIf Splitmusic(1) <> "mid" Then

Exit Sub

End If

Set Segment = Nothing

Set Segment = Loader.LoadSegment(App.Path & MUSIC_PATH & Filename)

' repeat midi file

Segment.SetLoopPoints 0, 0

Segment.SetRepeats 100

Segment.SetStandardMidiFile

Performance.PlaySegment Segment, 0, 0

Music_Playing = Filename

' Error handler

Exit Sub

errorhandler:

If InGame Then

HandleError "PlayMidi - Ingame = True - Map#= " & Player(MyIndex).Map & " - Filename = " & Filename & " - Filepath Length= " & Len(App.Path & MUSIC_PATH & Filename), "modSound", Err.Number, Err.Description, Err.Source, Err.HelpContext

Else

HandleError "PlayMidi - Ingame = False - Filename = " & Filename & " - Filepath Length= " & Len(App.Path & MUSIC_PATH & Filename), "modSound", Err.Number, Err.Description, Err.Source, Err.HelpContext

End If

Err.Clear

Exit Sub

End Sub

Search

Public Sub StopMidi()

and replace with

Public Sub StopMidi()

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

StopMp3

If Not (Performance Is Nothing) Then Performance.Stop Segment, Nothing, 0, 0

Music_Playing = vbNullString

' Error handler

Exit Sub

errorhandler:

HandleError "StopMidi", "modSound", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

Credits to Damian666

Thanks a lot.
This is great.
Though I was lazy so I clicked on the Download EO 2.3 with Mp3 link and pasted all my sprites and tilesets into that.

haha No Problem 😉 Im here to help

Uhm… one problem though.
I just tried to configure modconstants so it would work with my server but it won’t compile,
it says:

Compile error:

Sub or Function not defined

on

If Splitmusic(1) = “mp3” Then
        OpenDShowFile (App.Path & MUSIC_PATH & fileName)
        PlayMp3
        Exit Sub
    ElseIf Splitmusic(1) <> “mid” Then
        Exit Sub
    End If

OpenDShowFile is highlighted.

Added reference / moddxshow ???
If yes then idk why this appears what did you change

I’m using your client, so I think the reference and ModDxShow are already there.
Oh and I only changed the max amount maps, items and animations in ModConstants.
Nothing but that.

Alright, nevermind fixed it.
EDIT: Your EO with mp3 support client does not work. The mp3 won’t show up in the list.

EDIT: Your method works perfectly, decided to add it to my own client and it works fine.
Even works in menu. Though you will have to sacrifice your midi files for this. But there’s a better collection of mp3’s than midi’s so it’s worth it.

thanks for report and bad for double post 😉

Thanks, this is a great tutorial. But when I switch maps, even if both maps have the same background music, the song will stop and restart from the beginning again. Is there any way to make it so the song simply continues to play? This is what happened when I used midis, and I very much enjoyed that. If you could offer any assistance, I would really appreciate it.

Nice tutorial. This can be useful.

@Niffler:

Thanks, this is a great tutorial. But when I switch maps, even if both maps have the same background music, the song will stop and restart from the beginning again. Is there any way to make it so the song simply continues to play? This is what happened when I used midis, and I very much enjoyed that. If you could offer any assistance, I would really appreciate it.

Client side, in modHandleData, in sub HandleMapDone:

MusicFile = Trim$(Map.Music)
    If Not MusicFile = "None." Then
        PlayMidi MusicFile
    Else
        StopMidi
    End If

You should add a check there to check if the current song playing is the map music, and if that is the case dont stop the music.

That’s a good idea, thanks. But unfortunately I’m terrible at coding. What exactly would that check look like?

Would it be something sort of like this?  I really have no idea. It turns red when I type it in, so I obviously did something wrong.

MusicFile = Trim$(Map.Music)
If Not MusicFile = Music_Playing
    If Not MusicFile = "None." Then
        PlayMidi MusicFile
    Else
        StopMidi
    End If
End If

@Niffler:

That’s a good idea, thanks. But unfortunately I’m terrible at coding. What exactly would that check look like?

Would it be something like this? Or would that just break my game?

MusicFile = Trim$(Map.Music)
If Not MusicFile = Music_Playing
    If Not MusicFile = "None." Then
        PlayMidi MusicFile
    Else
        StopMidi
    End If
End If

This might work yeah (I’ve put a missing Then in, I’ve not testedthe code)

MusicFile = Trim$(Map.Music)
If Not MusicFile = Music_Playing Then
    If Not MusicFile = "None." Then
        PlayMidi MusicFile
    Else
        StopMidi
    End If
End If

Okay, thanks – I just tried putting the Then in. But it doesn’t seem to make any difference at all, the song still stops and restarts. Would Music_Playing, even be the right… thing? (do they call that a variable or a string or… I don’t even know.)

@Niffler:

Okay, thanks – I just tried putting the Then in. But it doesn’t seem to make any difference at all, the song still stops and restarts. Would Music_Playing, even be the right… thing? (do they call that a variable or a string or… I don’t even know.)

Put a breakpoint on this line:

If Not MusicFile = Music_Playing Then

Then try doing it, it will stop at that line and the line will turn yellow, when you move your mouse over MusicFile and Music_Playing you will see there comes a tooltip (text in a yellow bar), tell us the text it displays for both MusicFile and Music_Playing.

@Erwin:

Put a breakpoint on this line:

If Not MusicFile = Music_Playing Then

Then try doing it, it will stop at that line and the line will turn yellow, when you move your mouse over MusicFile and Music_Playing you will see there comes a tooltip (text in a yellow bar), tell us the text it displays for both MusicFile and Music_Playing.

Oh, that does seem a problem.

MusicFile = “Diagon Alley.mp3”
Music_Playing = “”

Change Music_Playing to CurSong

CurSong causes Compile Error: Variable not defined.

@Niffler:

CurSong causes Compile Error: Variable not defined.

Ah, keep it Music_Playing and replace PlayMidi with this:

Public Sub PlayMidi(ByVal Filename As String)
Dim Splitmusic() As String

    ' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    If Options.Music = 0 Then Exit Sub

    Splitmusic = Split(Filename, ".", , vbTextCompare)

    If Performance Is Nothing Then Exit Sub
    If LenB(Trim$(Filename)) < 1 Then Exit Sub
    If UBound(Splitmusic) <> 1 Then Exit Sub

    If Not FileExist(App.Path & MUSIC_PATH & Filename, True) Then Exit Sub

    If Not Music_On Then Exit Sub

    If Music_Playing = Filename Then Exit Sub

    If Splitmusic(1) = "mp3" Then
        OpenDShowFile (App.Path & MUSIC_PATH & Filename)
        PlayMp3
        Music_Playing = Filename
        Exit Sub
    ElseIf Splitmusic(1) <> "mid" Then
        Exit Sub
    End If

    Set Segment = Nothing
    Set Segment = Loader.LoadSegment(App.Path & MUSIC_PATH & Filename)

    ' repeat midi file
    Segment.SetLoopPoints 0, 0
    Segment.SetRepeats 100
    Segment.SetStandardMidiFile

    Performance.PlaySegment Segment, 0, 0

    Music_Playing = Filename

    ' Error handler
    Exit Sub
errorhandler:
    If InGame Then
        HandleError "PlayMidi - Ingame = True - Map#= " & Player(MyIndex).Map & " - Filename = " & Filename & " - Filepath Length= " & Len(App.Path & MUSIC_PATH & Filename), "modSound", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Else
        HandleError "PlayMidi - Ingame = False - Filename = " & Filename & " - Filepath Length= " & Len(App.Path & MUSIC_PATH & Filename), "modSound", Err.Number, Err.Description, Err.Source, Err.HelpContext
    End If
    Err.Clear
    Exit Sub
End Sub

Oh my goodness! This works! Thank you so much for all your help. You’re the best 😄
Would it be too much to ask you what exactly you did, in hopes that I could learn something?

Log in to reply