0

So I created an ASP.NET 4 application in VS2010, that needs to play sound to the end user, and it is working perfectly in my local development environment. The problem is the sound resource nor the Resources.resx is not being published to the server. Any idea why?

What I did:

1) Under Project  Properties  Recources I added my sound resource called: soundbyte (containing soundbyte.wav). I noticed this creates a Resource folder with the wav file and under my project a Resources.resx file referencing the file

2) In my code I play the file as follows:

    Dim audioFile = My.Resources. soundbyte
    Dim player = New Media.SoundPlayer(audioFile)
    player.Load()
    player.Play()
Off The Gold
  • 1,228
  • 15
  • 28

2 Answers2

1

In the Visual Studio Solution Explorer right-click on Resources.resx and select Properties. Build Action. Set to content.

EDIT: The following resource might also help. http://blog.andreloker.de/post/2010/07/02/Visual-Studio-default-build-action-for-non-default-file-types.aspx

Sam Leach
  • 12,746
  • 9
  • 45
  • 73
  • Sometimes, in the same window SamLeach talks about, I need set Copy to Output Directory to "CopyAlways" – twaldron May 09 '12 at 21:51
  • Still, no luck. The program doesn't compile when I change the Resources.resx to "content" I was able to get the the Resources.resx and the sound files to publish if I set the Copy to "CopyAlways" The code doesn't error after publishing, it just doesn't play the sound – Off The Gold May 10 '12 at 15:04
  • Actually, I found this article that points to the fact that it was probably working, but just entertaining the guys in the server room, but not working for the client. http://forums.asp.net/t/1377568.aspx/1 – Off The Gold May 10 '12 at 15:51
0

Ultimately, I found a way to play the sound to the client browser (as opposed to the server the asp app is running on) was to follow the techniques in this example: http://www.vbdotnetheaven.com/UploadFile/scottlysle/PlaySoundsInASPX09032006083212AM/PlaySoundsInASPX.aspx

But I found an even better way in my case was to use Javascript, which doesnt' require the Resources technique.

simply embed the sound on the page after the tag:

<embed src="Sounds/jump.wav" autostart=false width=1 height=1 id="sound1" enablejavascript="true">

Then in javascript setup the function:

function EvalSound(soundobj) {
    var thissound=document.getElementById(soundobj);
    thissound.Play();
}

Finally play the sound in the browser as needed in Javascript:

EvalSound('sound1');
Off The Gold
  • 1,228
  • 15
  • 28