Need help! Please reply ASAP!
Need help! Please reply ASAP!
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!
-
- Posts: 5426
- Joined: Sat Jul 24, 2004 12:12 pm
- Location: I'm a Paranoid
- Contact:
-
- Posts: 5426
- Joined: Sat Jul 24, 2004 12:12 pm
- Location: I'm a Paranoid
- Contact:
- grimdoomer
- Posts: 1440
- Joined: Mon Oct 09, 2006 4:36 pm
just make a button then when you click it display a open file dialog, then do
Code: Select all
WindowsMediaPlayer1.URL = OpenFileDialog.FileName
AI Zones in MP | Ambiance | Gravemind Beta v1.1
Aumaan Anubis wrote:Grimdoomer. The first person ever to mod Halo 2 Vista.
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.
Halo 3 Research Thread - Contribute to the research into Halo 3.
Well if you want it to play on startup you'll have to make a couple of changes: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!
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.
Halo 3 Research Thread - Contribute to the research into Halo 3.
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.
Halo 3 Research Thread - Contribute to the research into Halo 3.
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()
In both the bin> Debug and bin> Release folders.Eaton wrote:Where do I put the song file?
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.
Halo 3 Research Thread - Contribute to the research into Halo 3.