How to access wav files embedded in a resource file.

Mike Benton 96 Reputation points
2021-02-03T03:49:15.157+00:00

I am trying to access wav files embedded in a resource file. I am using Visual studio community (visual basic)
here is the code:

Public Class Form1
Sub PlayBackgroundSoundResource1()
My.Computer.Audio.Play(My.Resourse1.resx.alpha.wav,
AudioPlayMode.WaitToComplete)
End Sub

here is the solution explorer:
63138-image.png

I am getting the following error message:
BC30456 ‘alpha’ is not a member of ‘morse_code.My.Resources’.

Can you please help me with this or point me in the right direction.

Thanks,

Mike Benton

Developer technologies VB
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Castorix31 90,681 Reputation points
    2021-02-03T05:35:08.107+00:00

    This works for me :

    My.Computer.Audio.Play(My.Resources.alpha, AudioPlayMode.WaitToComplete)
    

  2. Mike Benton 96 Reputation points
    2021-02-03T17:34:24.203+00:00

    My.Computer.Audio.Play(My.Resources.alpha, AudioPlayMode.WaitToComplete)

    This is what I get with that change except the red underline is on My.Resources.alpha not AudioPlayMode.WaitToComplete and I still have the same error message.
    I'm not sure why it shows a different underline when I paste it here.


  3. Mike Benton 96 Reputation points
    2021-02-04T01:17:10.183+00:00

    Yes the resource has been added. I am using visual studio 2019 community and windows 10 64 bit.
    63721-image.png

    0 comments No comments

  4. Xingyu Zhao-MSFT 5,381 Reputation points
    2021-02-04T07:06:00.94+00:00

    Hi @Mike Benton ,

    Remove 'Resource1' folder and try adding wav files again.
    Right Click your project -> 'Properties' -> 'Resources' -> 'Add Resource' ...
    Then use:

    My.Computer.Audio.Play(My.Resources.alpha, AudioPlayMode.WaitToComplete)  
    

    Best Regards,
    Xingyu Zhao
    *
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  5. Mike Benton 96 Reputation points
    2021-02-10T19:24:53.013+00:00

    I finally got this to work by deleting the resources and creating a new resource file as follows:
    Projects - morse code properties - and then selecting the resource tab on the left and adding the
    resources again.
    There are several other ways to add a resource file but this is the one that worked for me.
    Thanks to all who were trying there best to help me figure this out.

    Mike Benton

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.