Page 1 of 1

Need help! Please reply ASAP!

Posted: Fri Dec 21, 2007 12:49 pm
by Eaton
Ok, I am trying to make a mp3 song file to play right when I open my application. I'm programming in Visual Basic and I cannot figure out how to do this. I need a reply like in the next hour, please. Thank you!

Posted: Fri Dec 21, 2007 12:59 pm
by Patrickssj6
Use the Windows Media Player COM component or convert it to wav and stream it.

Posted: Fri Dec 21, 2007 1:03 pm
by Eaton
:? Sorry. I'm really new to programming. Can you explain that in greater detail?

Posted: Fri Dec 21, 2007 1:12 pm
by Patrickssj6

Posted: Fri Dec 21, 2007 1:19 pm
by Eaton
That didn't work. I can't add a Windows Media Player control. I use Visual Studio 2008. Is is this hard to add s simple audio file?

Posted: Fri Dec 21, 2007 1:25 pm
by grimdoomer
just make a button then when you click it display a open file dialog, then do

Code: Select all

WindowsMediaPlayer1.URL = OpenFileDialog.FileName

Posted: Fri Dec 21, 2007 1:29 pm
by Eaton
I don't want it to play when I press the button. I want it to play immediately once I open the program. I need to go. Someone please tell me how to do this. I am just starting off in Visual Basic and I need it as simple as it can get. Thank you!

Posted: Fri Dec 21, 2007 1:30 pm
by Prey
Here's something I made a very long time ago, and didn't fully understand at the time either (hence possible bad coding-practises!..).. but it should do for whatever is urgent.. if you continue it though I would advise researching how to properly use the 2 dll's I import first, just to make sure if there is a better way..

Posted: Fri Dec 21, 2007 2:09 pm
by Eaton
Hmm... Interesting. I'll try that. I'm off of my laptop so I'll have to do it later. What am I exactly supposed to do with this? I am making an Christmas application for my friend and I need it done ASAP. Anyway, I hope this works and thank you very much for helping!

Posted: Fri Dec 21, 2007 2:28 pm
by Prey
Eaton wrote:Hmm... Interesting. I'll try that. I'm off of my laptop so I'll have to do it later. What am I exactly supposed to do with this? I am making an Christmas application for my friend and I need it done ASAP. Anyway, I hope this works and thank you very much for helping!
Well if you want it to play on startup you'll have to make a couple of changes:

1) Double-click the form to bring you to Form1_Load in code, and place in there the code currently in the 'play' button, minus the openfiledialog stuff.

2) Place the music file in the same directory as the app, then you'll have to replace the part where the filename from the ofd was used, with the new filename. So "Application.StartupPath & "\whatever.mp3"

Posted: Fri Dec 21, 2007 4:54 pm
by Eaton
That is still a bit hard for me to understand. Can you make it a bit simpler?

Posted: Fri Dec 21, 2007 5:08 pm
by Prey
Hmm looking over the code again, what I said was slightly confusing.. Well here's the code you would need anyway, just make sure to change the "something.mp3" to whatever your song is called:

Code: Select all

Public Class Form1

    'the filename is the location of the file the app will play
    Dim FileName As String

    'this will store our return value from the mciSendString function
    Dim ReturnValue As Integer

    'this will store the data returned from the lpstrReturnString parameter.
    'it will have a 128 character buffer
    Dim ReturnData As String = Space(128)

    'this will store our return string from the mciGetErrorString function.
    'it will have a 128 character buffer
    Dim Status As String = Space(128)

    'a boolean is a true or false statement. we will get true if
    'our mciGetErrorString successfully determines the string it
    'recieves from the mciSendString function
    Dim Success As Boolean

    'these 2 functions use .dll's that should be on evey windows running pc
    Private Declare Function mciSendString Lib "winmm.dll" Alias _
    "mciSendStringA" (ByVal lpstrCommand As String, ByVal _
            lpstrReturnString As String, ByVal uReturnLength As Integer, _
                ByVal hwndCallback As Integer) As Integer

    Private Declare Function mciGetErrorString Lib "winmm.dll" Alias _
        "mciGetErrorStringA" (ByVal dwError As Integer, ByVal lpstrBuffer _
            As String, ByVal uLength As Integer) As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        FileName = Chr(34) & Application.StartupPath & "\something.mp3" & Chr(34)

        ReturnValue = mciSendString("open " & FileName & " type mpegvideo alias oursong", 0, 0, 0)
        ReturnValue = mciSendString("play oursong", 0, 0, 0)

        ' Optional.
        Success = mciGetErrorString(ReturnValue, Status, 128)
        TextBox2.Text = Status

    End Sub

End Class

Posted: Fri Dec 21, 2007 5:14 pm
by Dagger13
wow prey i think thats a little advanced for a beginner

Posted: Fri Dec 21, 2007 5:45 pm
by Eaton
Where do I put the song file?

Posted: Fri Dec 21, 2007 6:01 pm
by Eaton
I think that this is just a bit complicated for me at the moment. This is my very first application and I guess making a simple song play on startup is not in my league. Oh well...

Posted: Sat Dec 22, 2007 3:19 am
by Prey
That's because you're trying to play an .mp3. If the song were a .wav on the other hand...

Code: Select all

        Dim sp As New Media.SoundPlayer(Application.StartupPath & "\something.wav")
        sp.PlayLooping()
Eaton wrote:Where do I put the song file?
In both the bin> Debug and bin> Release folders.

Posted: Sat Dec 22, 2007 6:42 am
by Eaton
Ok. I already sent it to my friends so I'll do it in a future release. Thank you so much for helping! I really appreciate it!