سؤال

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()
هل كانت مفيدة؟

المحلول 2

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');

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top