Results 1 to 4 of 4

Thread: [RESOLVED] How to addressing wav and gif from resources?

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Resolved [RESOLVED] How to addressing wav and gif from resources?

    Hi, these two lines of codes already tested and works properly. What if you include those *.wav(s) and *.gif(s) in app resources? How can we address them using My.Recourses?

    Code:
    Dim animatedImage As New Bitmap(Application.StartupPath & "\splash.gif")
    Code:
    My.Computer.Audio.Play("select.wav")
    Need to achieve something independent and app-included like this: (Following codes are examples and errors surly pop up)

    Code:
    Dim animatedImage As New Bitmap(My.Resources.splash)
    Code:
    My.Computer.Audio.Play(My.Resources.select)

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

    Re: How to addressing wav and gif from resources?

    Firstly, if errors pop up and you want us to help you fix them, don't you think it would be a good idea to provide us with the error messages? That's just common sense.

    When you add an existing file to your Resources, the type of property generated in My.Resources will depend on the type of file you added. You can see the type of each property just like you can any other in code. If you do this:
    vb.bet Code:
    1. Dim x = My.Resources.splash
    then you'll be able to see what type that property is as you type or by checking the type inferred for x. For a GIF file, I'd expect the property to be type Image and the object it returns to be type Bitmap.

    For the WAV, I would expect the property to be either Byte() or perhaps UnmanagedMemoryStream or the like. In either case, you should be able to pass it directly to Play as long as you provide a second argument of type AudioPlayMode. I suspect that the error message actually told you that, but I can only guess.
    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

  3. #3

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Re: How to addressing wav and gif from resources?

    I might be a bit less artful in describing things, sorry for that

    I achieve correct results for first part of the thread. You can call a wave file anywhere in your WinForms VB.NET projects from My.Resources via
    Code:
    My.Computer.Audio.Play(My.Resources.ButtonClick, AudioPlayMode.Background)
    Second part which was GIF files, Difficult part is, Application runs and do things with no errors (To mention) Only additional information is

    Instead of
    Code:
    Dim animatedImage As New Bitmap(Application.StartupPath & "\splash.gif")
    I used
    Code:
    Dim animatedImage As New Bitmap(My.Resources.splash, My.Resources.splash.Size)
    The goal is to "play" GIF file once in a picturebox then proceed. Problem is only the first frame of GIF will be shown. Should I vast the gif array as its length, if so HOW?

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

    Re: How to addressing wav and gif from resources?

    Quote Originally Posted by pourkascheff View Post
    I used
    Code:
    Dim animatedImage As New Bitmap(My.Resources.splash, My.Resources.splash.Size)
    The goal is to "play" GIF file once in a picturebox then proceed. Problem is only the first frame of GIF will be shown. Should I vast the gif array as its length, if so HOW?
    I thought we already covered this:
    vb.net Code:
    1. Dim animatedImage = My.Resources.splash
    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

Tags for this Thread

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