-
[02/03] Sounds and Video
Hello, I am trying to figure out how to add sounds to a form...I've searched the forums and found nothing really. I have VB.Net 2003...dunno if that matters to you :p. I also would like to know how to add in a video file if it's possible...
I just really need an example of the code, it would be appreciated.
-
Re: [02/03] Sounds and Video
-
Re: [02/03] Sounds and Video
-
Re: [02/03] Sounds and Video
whew! this should be easy. hold on a second
-
Re: [02/03] Sounds and Video
Alright.. tell me if this works
El Function
Code:
Public Declare Function playa Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Sub PlayWav(sFile As String)
If Dir(sFile$) <> "" Then Call playa(sFile, SND_FLAG)
End Sub
Use it
Code:
'// plays C:\west.wav
Call PlayWav("C:\west.wav")
-
Re: [02/03] Sounds and Video
On .net 2005 you can use "my.computer.audio"
on .net 2003, i'm not sure.
Maybe you should check this out.
http://msdn2.microsoft.com/en-us/library/ms867138.aspx
-
Re: [02/03] Sounds and Video
Well, most of it works. This seems to get the error underline thingy though (bolded):
Quote:
Originally Posted by Fromethius
Code:
If Dir(sFile$) <> "" Then Call playa(sFile, SND_FLAG)
End Sub
-
Re: [02/03] Sounds and Video
Code:
Private Const SND_FLAG = &H1 Or &H2
??
-
Re: [02/03] Sounds and Video
.NET 1.x has no real support for sound. You can use the PlaySound API yourself, examples of which are plentiful on the forum, or you can use a third-party wrapper class. Follow the Mentalis link in my signature and you'll find just such a class.
As for video, again it helps to be a little more specific. There are exactly 2.75 squintillion different video formats for PC. Do you want to display a Flash file, an AVI, some other specific format or many different formats? There won't be any one way to handle every format but there are media players that can handle most of the common ones. Unless you want to do a lot of work yourself you'll want to add a third party component to your form to handle the playback which you can than control in code or provide UI controls for the user. The easiest option is Windows Media Player because it is alreday present on every Windows system. You can add the WMP ActiveX control to your Toolbox (right-click, Add/Remove) from the COM Components tab. You can then add an instance to your form like any other control. You should then read the documentation on MSDN, use Intellisense to see what members it has and search the forum to see what issues others have had and how they were solved.
-
Re: [02/03] Sounds and Video
Fromethius, it works now, thank you. :)
As for video type, AVI or .Mov...(the video is made in Windows Movie Maker (by me) and there are a variety of save formats)
-
Re: [02/03] Sounds and Video
just curious.. why not get the latest visual basic .net? (ie: 2005)
-
Re: [02/03] Sounds and Video
Well, (as far as I know) I'd have to buy another copy of VB.Net and lose my projects, and I don't have the money right now. :P
Anyways, I've made a game...thingy, and the collision detection doesnt seem to be working. This is my code (Its a projectile type thing being shot):
VB Code:
If PictureBox13.Left = PictureBox8.Left Or PictureBox13.Left = Val(PictureBox8.Left) + 96 Then
If Val(PictureBox13.Top) = Val(PictureBox8.Top) > -128 Then
If Val(PictureBox13.Top) <= Val(PictureBox8.Top) Then
P2.Text = Val(P2.Text) - 10
PictureBox13.Visible = False
End If
End If
End If
Picturebox13 is the projectile and Picturebox8 is the player 2/AI...P2.text is the health. 128 is the height of the picturebox (8).
-
Re: [02/03] Sounds and Video
Not to say that you necessarily should ditch VS.NET 2003 if you paid for it and it does what you want but you can get VB 2005 Express for free. It's a fairly powerful IDE, although it does lack some of the features of its big brothers. It will upgrade your existing projects to the new format and many won't erquire any changes at all, though some probably will require minor changes. It's not a bad idea to give it a try but note that the project upgrade process is not reversible so make sure you keep a backup copy of your project if you're going to want to open it in VS.NET 2003 again. This also means that any changes you make in 2005 cannot be transferred back to 2003.
Note that the upgrade process being irreversible means that the IDE will not do it for you. You can actually edit some text files manually and then open your project in 2003 again, but there's every chance that any code you write in 2005 will not be compatible because there have been language and class library changes.
-
Re: [02/03] Sounds and Video
I will go search for 2005...(or do I have to order it somehow? :p)
Collision detection frustrates me. :(
EDIT: I think I found it...would this be it?
-
Re: [02/03] Sounds and Video
That's the express edition which is free.
You can buy the whole package.It's called Visual Studio(has all languages).
Both use the 2.0 Framework.
-
1 Attachment(s)
Re: [02/03] Sounds and Video
There's a VB.NET Games Programming tutorial link in my signature. It has some information on collision detection but I'm not sure what. Having said that, it's relatively easy with two controls:
VB Code:
Private Function DetectCollision(ByVal ctl1 As Control, ByVal ctl2 As Control) As Boolean
Return ctl1.Bounds.IntersectsWith(ctl2.Bounds)
End Function
Have a good look at the attched image though, to see exactly what is detected. If you want both cases to be detected as a collision then you'll need to create a new Rectangle for one of the controls that is one pixel larger in all directions.
-
Re: [02/03] Sounds and Video
Well, I got 2005...what stinks is that I paid 75$ or so for 2003 and 2005 was free. :(
-
Re: [02/03] Sounds and Video
same here.. =/ That was a while ago though
-
Re: [02/03] Sounds and Video
Well, collision detection is working now. Thanks for all your help guys, though sounds aren't working for 2005...I'm trying this:
VB Code:
My.Computer.Audio.Play("intro.wav")
Its in the bin folder...it doesnt work when run inside and outside (built) .Net. It gives this error: "Sound API only supports playing PCM wave files.".
-
Re: [02/03] Sounds and Video
Code:
Dim mediaSoundPlayer As New System.Media.SoundPlayer
If openFile.ShowDialog() = Windows.Forms.DialogResult.OK Then
mediaSoundPlayer.SoundLocation = openFile.FileName
mediaSoundPlayer.Play()
End If
mediaSoundPlayer.Play()
Bits of code that can help :)
-
Re: [02/03] Sounds and Video
Well, I know my code is correct (99% sure), but I don't understand why I get this error: "Sound API only supports playing PCM wave files."
-
Re: [02/03] Sounds and Video
Presumably your file is not a PCM wave file, whatever exactly that is. What happens if you double-click that file in Windows Explorer? Does it play properly? If so then I guess Windows has support for different wave formats but the API used by that method doesn't. Perhaps you should Google to find out exactly what a PCM wave file is and if and how it differs from any other type of wave file.
Edit: Just took my own advice and found that wave files normally store data in the uncompressed PCM format but can contain compressed audio too. That I didn't know, but it suggests that perhaps your file is compressed and Windows, or at least the API being used by My.Computer.Audio.Play, supports only the uncompressed PCM format.
-
Re: [02/03] Sounds and Video
So is the a converter/decompresser? I'll search..:p
-
Re: [02/03] Sounds and Video
So how do you upload videos onto a game from Windows Movie Maker?
-
Re: [02/03] Sounds and Video
Anyone know? (sorry for bumping it)
-
Re: [02/03] Sounds and Video
None? Please I nees to know! :D