Need help! Please reply ASAP!

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
User avatar
Eaton




Enthraller

Posts: 1639
Joined: Thu Jun 14, 2007 4:16 pm
Location: USA

Need help! Please reply ASAP!

Post 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!
Patrickssj6




Pi Collaborator

Posts: 5426
Joined: Sat Jul 24, 2004 12:12 pm
Location: I'm a Paranoid
Contact:

Post by Patrickssj6 »

Use the Windows Media Player COM component or convert it to wav and stream it.
...left for good
User avatar
Eaton




Enthraller

Posts: 1639
Joined: Thu Jun 14, 2007 4:16 pm
Location: USA

Post by Eaton »

:? Sorry. I'm really new to programming. Can you explain that in greater detail?
Patrickssj6




Pi Collaborator

Posts: 5426
Joined: Sat Jul 24, 2004 12:12 pm
Location: I'm a Paranoid
Contact:

Post by Patrickssj6 »

...left for good
User avatar
Eaton




Enthraller

Posts: 1639
Joined: Thu Jun 14, 2007 4:16 pm
Location: USA

Post 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?
User avatar
grimdoomer




System Engineer

Posts: 1440
Joined: Mon Oct 09, 2006 4:36 pm

Post 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
Image
AI Zones in MP | Ambiance | Gravemind Beta v1.1
Aumaan Anubis wrote:Grimdoomer. The first person ever to mod Halo 2 Vista.
User avatar
Eaton




Enthraller

Posts: 1639
Joined: Thu Jun 14, 2007 4:16 pm
Location: USA

Post 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!
User avatar
Prey




Connoisseur Snitch! Pyre Articulatist 500

Posts: 1026
Joined: Wed Dec 27, 2006 6:49 am
Location: UK
Contact:

Post 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..
Attachments
music player project.zip
(56.19 KiB) Downloaded 14 times
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
User avatar
Eaton




Enthraller

Posts: 1639
Joined: Thu Jun 14, 2007 4:16 pm
Location: USA

Post 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!
User avatar
Prey




Connoisseur Snitch! Pyre Articulatist 500

Posts: 1026
Joined: Wed Dec 27, 2006 6:49 am
Location: UK
Contact:

Post 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"
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
User avatar
Eaton




Enthraller

Posts: 1639
Joined: Thu Jun 14, 2007 4:16 pm
Location: USA

Post by Eaton »

That is still a bit hard for me to understand. Can you make it a bit simpler?
User avatar
Prey




Connoisseur Snitch! Pyre Articulatist 500

Posts: 1026
Joined: Wed Dec 27, 2006 6:49 am
Location: UK
Contact:

Post 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
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

Post by Dagger13 »

wow prey i think thats a little advanced for a beginner
Last edited by Dagger13 on Fri Dec 21, 2007 6:16 pm, edited 1 time in total.
Image(An Old one.)
User avatar
Eaton




Enthraller

Posts: 1639
Joined: Thu Jun 14, 2007 4:16 pm
Location: USA

Post by Eaton »

Where do I put the song file?
User avatar
Eaton




Enthraller

Posts: 1639
Joined: Thu Jun 14, 2007 4:16 pm
Location: USA

Post 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...
User avatar
Prey




Connoisseur Snitch! Pyre Articulatist 500

Posts: 1026
Joined: Wed Dec 27, 2006 6:49 am
Location: UK
Contact:

Post 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.
Last edited by Prey on Sat Dec 22, 2007 7:14 am, edited 1 time in total.
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
User avatar
Eaton




Enthraller

Posts: 1639
Joined: Thu Jun 14, 2007 4:16 pm
Location: USA

Post 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!
Post Reply