Results 1 to 26 of 26

Thread: [02/03] Sounds and Video

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

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

  2. #2
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [02/03] Sounds and Video

    Wav's or mp3's?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

    Re: [02/03] Sounds and Video

    Wavs.

  4. #4
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [02/03] Sounds and Video

    whew! this should be easy. hold on a second

  5. #5
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    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")

  6. #6
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    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

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

    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

  8. #8
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [02/03] Sounds and Video

    Code:
    Private Const SND_FLAG = &H1 Or &H2
    ??

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

    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)

  11. #11
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [02/03] Sounds and Video

    just curious.. why not get the latest visual basic .net? (ie: 2005)

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

    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:
    1. If PictureBox13.Left = PictureBox8.Left Or PictureBox13.Left = Val(PictureBox8.Left) + 96 Then
    2.             If Val(PictureBox13.Top) = Val(PictureBox8.Top) > -128 Then
    3.                 If Val(PictureBox13.Top) <= Val(PictureBox8.Top) Then
    4.                     P2.Text = Val(P2.Text) - 10
    5.                     PictureBox13.Visible = False
    6.                 End If
    7.             End If
    8.         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).
    Last edited by Aloshi; Oct 17th, 2006 at 06:14 PM.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

    Re: [02/03] Sounds and Video

    I will go search for 2005...(or do I have to order it somehow? )

    Collision detection frustrates me.

    EDIT: I think I found it...would this be it?
    Last edited by Aloshi; Oct 17th, 2006 at 06:51 PM.

  15. #15
    Lively Member
    Join Date
    Aug 2006
    Posts
    72

    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.

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Private Function DetectCollision(ByVal ctl1 As Control, ByVal ctl2 As Control) As Boolean
    2.     Return ctl1.Bounds.IntersectsWith(ctl2.Bounds)
    3. 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.
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

    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.

  18. #18
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [02/03] Sounds and Video

    same here.. =/ That was a while ago though

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

    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:
    1. 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.".
    Last edited by Aloshi; Oct 18th, 2006 at 03:09 PM.

  20. #20
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    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

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

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

  22. #22
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Last edited by jmcilhinney; Oct 18th, 2006 at 05:33 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

    Re: [02/03] Sounds and Video

    So is the a converter/decompresser? I'll search..

  24. #24
    New Member
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    2

    Re: [02/03] Sounds and Video

    So how do you upload videos onto a game from Windows Movie Maker?

  25. #25

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Location
    Over there. *points*
    Posts
    24

    Re: [02/03] Sounds and Video

    Anyone know? (sorry for bumping it)

  26. #26
    New Member
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    2

    Re: [02/03] Sounds and Video

    None? Please I nees to know!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width