[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

The silence is deafening

Hi

I am trying to play an embedded wave file in my application.    I can do it, but only if I don't rename the application.  If I create a brand new application and put the following code in the "Form Load Event",  then everything is fine.


If I rename the solution,  then it fails.   Here is the code. I am frustrated.

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
           Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(My.Application.Info.AssemblyName & ".button-13.wav")
        My.Computer.Audio.Play((Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(My.Application.Info.AssemblyName & ".button-13.wav")), AudioPlayMode.Background)
End Sub
0
peispud
Asked:
peispud
  • 3
  • 3
  • 2
  • +2
2 Solutions
 
AndyAinscowCommented:
Display a messagebox with 'My.Application.Info.AssemblyName' as the message AFTER renaming.  Does it show the original name or the new name?
0
 
Arthur_WoodCommented:
Since you renamed the assembly, did you also rememebr to rename the wav file:

My.Application.Info.AssemblyName & ".button-13.wav"

AW
0
 
Bob LearnedCommented:
The resource is {namespace}.{resource}, not {assembly}.{resource}.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
peispudAuthor Commented:
Ok

I have created a project and closed the project withone even one  line of code. This was an opportunity to rename a "clean project".  I called the project  "Test3".  I found help on Microsoft for embedded files and adapted it to my application.

http://msdn.microsoft.com/en-us/library/3w5b27z4.aspx#Y0

Below is the code that I used.  It works fine if  I create a new project and run it so long as the  project is not renamed.  It does not work on a project called "Test3" created in the manner that I mentioned above.

I've been looking at everyone's advice,  but am still stuck.

By the way,  the following line of code evaluates to "nothing".  I realize that this is the problem, but I do not know the solution.  I expect that "TheLearnedOne" is probably on the right track but  but I was unable to apply that solution in VB.Net 2010.  Hoping for more help.

Dim s As System.IO.Stream = a.GetManifestResourceStream(AssembleyName & ".fanfare.wav")  



Public Class Form1

    'Declare constants
    Public Const SND_ASYNC As Int32 = 1
    Public Const SND_MEMORY As Int32 = 4
    Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySound" (ByVal data() As Byte, ByVal hMod As IntPtr, ByVal dwFlags As Int32) As Boolean

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim a As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
        Dim AssembleyName As String = My.Application.Info.AssemblyName
        Dim s As System.IO.Stream = a.GetManifestResourceStream(AssembleyName & ".fanfare.wav")
        Dim player As SoundPlayer = New SoundPlayer(s)
        player.Play()
    End Sub
 
End Class
0
 
Bob LearnedCommented:
Try this, and tell me what the resulting resource name is:

    Dim resourceName As String = Me.GetType().Namespace + ".fanfare.wav"

Try this, and tell me what the resource names are:

    Dim list As List(Of String) = a.GetManifestResourceNames().ToList()
0
 
peispudAuthor Commented:
Again, the project name is "Test3"

Dim resourceName As String = Me.GetType().Namespace + ".fanfare.wav"
resourceName  = "WindowsApplication2.fanfare.wav"

 Dim list As List(Of String) = a.GetManifestResourceNames().ToList()
(0)      "WindowsApplication2.Resources.resources"      String
(1)      "WindowsApplication2.fanfare.wav"      String
0
 
AndyAinscowCommented:
>>I expect that "TheLearnedOne" is probably on the right track

:-(   Obviously you didn't realise the significance of my first comment.  It is pointing out you might well rename the app BUT not the assembly.
0
 
CodeCruiserCommented:
After renaming the project/solution, did you check the RootNamespace of the project? Is it renamed as well?
0
 
peispudAuthor Commented:
Assembly name     :    Test3
Root Namespace    :    WindowsApplication2

I changed the RootNamespace to Test3 and that fixed everything.   Thank you all very much!!

I have to learn more about RootNameSpace..   Does changing the RootNameSpace impact my project in any way?  

Is this a bug ?     Remember that I created a project and only gave the name Test3 when I was prompted for a project name on closing VB.net.   I didn't rename it after saving it.
0
 
CodeCruiserCommented:
When you create a project from scratch, RootNamespace is same as project name. Not sure what happened when copying a project. Changing rootnamespace will have impact in that every class in your project will move to that new rootnamespace. All your imports or declarations will need to change.
0
 
AndyAinscowCommented:
>>I can do it, but only if I don't rename the application.

?  Did you change the application name (eg. with explorer) or rename the project.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now