Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Adding Mp3 To EO2.3


Wortel Angels
 Share

Recommended Posts

Thanks Damian666 for the other tutorial

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

First download: [modDxShow.bas](http://www.file-upload.net/download-6954302/modDxShow.bas.html) 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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

@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.
Link to comment
Share on other sites

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

```
Link to comment
Share on other sites

@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
```
Link to comment
Share on other sites

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.)
Link to comment
Share on other sites

@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.
Link to comment
Share on other sites

@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 = ""
Link to comment
Share on other sites

@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
```
Link to comment
Share on other sites

@Niffler:

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

Well, I think you understand the things with the End If case, which checks the map song with the playing song, but I only added Music_Playing = Filename in:
```
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
```
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...