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

Adding a Jukebox.


Carim123
 Share

Recommended Posts

Adding a Jukebox

First off, I am only going to give you the code for the Jukebox. I don't care whether you use another form, embed it into the menu, whatever, that's up to you to decide. If you have trouble with that, don't bug me about it. If you're having trouble with the actual code itself, then bug me.

In theory, all this does is echo what it has in Map Properties, while adding a few extra features.

First off, if you making a new form, or adding it to frmMain, add this under Option Explicit, in the General Declarations.

```
Private Declare Function SendMessageByString _
                        Lib "user32" _
                        Alias "SendMessageA" _
                        (ByVal hWnd As Long, _
                          ByVal wMsg As Long, _
                          ByVal wParam As Long, _
                          ByVal lParam As String) _
As Long

Private Const LB_SELECTSTRING = &H18C
```
This is the basis of our search funtion. Now, where ever you are, add a textbox, a listbox, and three command buttons. You can substitute the command buttons for animated pictures, or images.

Name the textbox "txtFind".
Name the listbox "lstJuke".
Name the three command buttons "cmdPlay", "cmdStop", and "cmdMap". Give them a caption to their function. Name it whatever you like.

On your Form_Load (frmMain_Load, in my case.) add…
```
Dim i As Long, E As String

'Start Jukebox
    If Not hasPopulated Then
        PopulateLists
    End If

    lstJuke.Clear
    For i = 1 To UBound(musicCache)
    E = Mid(musicCache(i), 1, (Len(musicCache(i))) - 4)
        lstJuke.AddItem E
    Next
'End Jukebox
```
If you'll notice, you'll see that this is more or less the same as the Map Properties music loading. Useful bit of code. :D

Now, under txtFind_Change add:
```
    Dim lngEntryNum    As Long
    Dim strTextToFind  As String

    strTextToFind = txtFind.text

    lngEntryNum = SendMessageByString(lstJuke.hWnd, _
                                      LB_SELECTSTRING, _
                                      0, _
                                      strTextToFind)
```This is for the search function. That's right, you can search your music as you play!

Now, Under cmdPlay…
```
If Options.Music = 1 Then
    StopMidi
    PlayMidi lstJuke.List(lstJuke.ListIndex) & ".mid"
    Else
    StopMidi
    End If
```
Under cmdStop…
```
StopMidi
```
And under cmdMap…
```
Dim MusicFile As String

If Options.Music = 1 Then
    StopMidi
    ' start music playing
    MusicFile = Trim$(Map.Music)
    If Not MusicFile = "None." Then
        PlayMidi MusicFile
    Else
        StopMidi
    End If
    Else
    Exit Sub
    End If
```
And, that should be it. If I've forgotten anything tell me, I don't think I have.
You now have a Jukebox!

Please, give me credit.
Link to comment
Share on other sites

@Darth:

> It says lstJuke is undefined, now, I know I'm not the best with vb6, but i do believe I followed this correctly, do you have any idea where I may have slipped up?

> This is the basis of our search funtion. Now, where ever you are, add a textbox, a listbox, and three command buttons. You can substitute the command buttons for animated pictures, or images.
>
> Name the textbox "txtFind".
> Name the listbox "lstJuke".
> Name the three command buttons "cmdPlay", "cmdStop", and "cmdMap". Give them a caption to their function. Name it whatever you like.
Link to comment
Share on other sites

@Darth:

> It says lstJuke is undefined, now, I know I'm not the best with vb6, but i do believe I followed this correctly, do you have any idea where I may have slipped up?

That would have never happened if you used the great Automagic system made by our very own mod, Soul. Do you think you could make an Automagic installer Hamster Boy??? Anyway, nice tut.
Link to comment
Share on other sites

@D.J.:

> That would have never happened if you used the great Automagic system made by our very own mod, Soul. Do you think you could make an Automagic installer Hamster Boy??? Anyway, nice tut.

No thanks, this is too simple to make the hassle.
Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...
Ah, thanks, I tried this again after a while, and whatever I messed up with last time, I got it right this time, and it works perfectly!  Plus, it's extra incentive for me to start messing with the gui, so I can replace the ugly "Open" Command Button I made to test it!  Thanks for the cool feature, I really like that you can search for the track you want to hear!  Oh, one more thing.  Is there a way to hide the ".mid" part on the list?  It's not extremely important, as of right now, but it would just look a bit better, at least to me.
Link to comment
Share on other sites

@Darth:

> Ah, thanks, I tried this again after a while, and whatever I messed up with last time, I got it right this time, and it works perfectly!  Plus, it's extra incentive for me to start messing with the gui, so I can replace the ugly "Open" Command Button I made to test it!  Thanks for the cool feature, I really like that you can search for the track you want to hear!  Oh, one more thing.  Is there a way to hide the ".mid" part on the list?  It's not extremely important, as of right now, but it would just look a bit better, at least to me.

To hide the .mid, change the Dim i As Long to;

```
    Dim i As Long, E As String
```
Then under    For i = 1 To UBound(musicCache), to the Next, remove the middle, and change it to;

```
    E = Mid(musicCache(i), 1, (Len(musicCache(i))) - 4)
        lstJuke.AddItem E
```
Link to comment
Share on other sites

There's now a problem with the code; it doesn't play the midi when you hit Play.  I've been trying to find the solution, but to no avail, I can't find a way too fix it.  I'll keep trying, as I'm sure it's right under my nose.  I'll post it if I can find the answer!
Link to comment
Share on other sites

@Darth:

> There's now a problem with the code; it doesn't play the midi when you hit Play.  I've been trying to find the solution, but to no avail, I can't find a way too fix it.  I'll keep trying, as I'm sure it's right under my nose.  I'll post it if I can find the answer!

Ah, sorry, another thing I forgot to give you…

Change

```
                PlayMidi lstJuke.List(lstJuke.ListIndex)
```
to…

```
                PlayMidi lstJuke.List(lstJuke.ListIndex) & ".mid"
```
Link to comment
Share on other sites

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...