{"id":579,"date":"2008-10-13T07:42:05","date_gmt":"2008-10-13T12:42:05","guid":{"rendered":"http:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/579"},"modified":"2008-10-13T07:42:05","modified_gmt":"2008-10-13T12:42:05","slug":"how-to-play-an-audio-file-in-silverlight-part-2","status":"publish","type":"post","link":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/579","title":{"rendered":"How to play an Audio File in Silverlight, Part 2"},"content":{"rendered":"

I was asked in a comment<\/a> how to play a sound from a stream, from an embedded resource in Silverlight or WPF. <\/p>\n

My answer is that I wouldn’t use an embedded resource, instead I’d suggest using the “Content” Build Action as shown below:<\/p>\n

\"image\" <\/p>\n

I’ve set the explosion.mp3 file’s Build Action to “Content”. Then, using my audio playing technique, I call the function:<\/p>\n

PlayAudio(\"\/explosion.mp3\"<\/span>, .5);<\/pre>\n

(The .5 sets the volume.)<\/p>\n

You might look at MediaStreamSource<\/a> (set via the MediaElement’s SetSource property). <\/p>\n

There’s an example dealing with MP3 files here<\/a>. Realize that path requires that your code fully take over the the responsibility for streaming — including understanding the low-level details of the audio\/video format. For example, you would need to know how to decode an MP3 file.<\/p>\n","protected":false},"excerpt":{"rendered":"

I was asked in a comment how to play a sound from a stream, from an embedded resource in Silverlight or WPF. My answer is that I wouldn’t use an embedded resource, instead I’d suggest using the “Content” Build Action as shown below: I’ve set the explosion.mp3 file’s Build Action to “Content”. Then, using my […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[4],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pd5QIe-9l","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":577,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/577","url_meta":{"origin":579,"position":0},"title":"Silverlight Game Programming: Playing an Audio File","date":"October 12, 2008","format":false,"excerpt":"In my recent Silverlight game, there are a variety of sound effects that occur from bullet fires to explosions. Most of the audio files are brief, lasting only for a second or less on average. I had a few options -- put a MediaElement directly on the UI (in XAML)\u2026","rel":"","context":"In "Coding"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2008\/10\/image2.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1076,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/1076","url_meta":{"origin":579,"position":1},"title":"How to embed and use the Google Web Fonts in Silverlight","date":"May 23, 2010","format":false,"excerpt":"There are a few steps necessary to using one of the Google Web Fonts in Silverlight. Step 1 Go to the directory of web fonts here. \u00a0 Step 2 Pick your favorite font and click the embed link: Step 3 Verify the license is acceptable to your needs. Step 4\u2026","rel":"","context":"In "Silverlight"","img":{"alt_text":"SNAGHTML5afad2c6","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2010\/05\/SNAGHTML5afad2c6.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1016,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/1016","url_meta":{"origin":579,"position":2},"title":"Silverlight vs. Flash vs. Photoshop Text Rendering","date":"March 24, 2010","format":false,"excerpt":"Curious about text rendering characteristics between Flash 10, Silverlight 4.0 and Photoshop, I created two small applications, one in Flash CS 4, and one in Visual Studio 2010. The Silverlight 4.0 tests are using the release candidate which was current as of March 23, 2010. I used Times New Roman\u2026","rel":"","context":"In "Coding"","img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2010\/03\/image_thumb.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":670,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/670","url_meta":{"origin":579,"position":3},"title":"Silverlight: Dynamically creating XAML elements at runtime","date":"January 19, 2009","format":false,"excerpt":"Given the following XML file: <\/Canvas> <\/asset> <\/assets> It\u2019s easy enough to create reusable assets in Silverlight and load them on demand from XML, and refer to the\u2026","rel":"","context":"In "Coding"","img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2009\/01\/image8.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":723,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/723","url_meta":{"origin":579,"position":4},"title":"Silverlight Stopwatch class in C#","date":"March 1, 2009","format":false,"excerpt":"I needed a simple method for doing some timings in Silverlight. Silverlight lacks the high performance query counter that is available natively in Windows (and available in .NET 3.5 for example), but it does have a TickCount. My code (mostly) mirrors the existing .NET Stopwatch class using the TickCount property\u2026","rel":"","context":"In "Coding"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":633,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/633","url_meta":{"origin":579,"position":5},"title":"A Silverlight 2 TilePanel","date":"December 14, 2008","format":false,"excerpt":"You may notice that the Silverlight TileBrush is missing some key properties which would enable it to actually tile a brush. The WPF TileBrush has properties such as TileMode, Viewbox, and ViewportUnits that can be used to tile an image as a fill or as a background for a UIElement.\u2026","rel":"","context":"In "Coding"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2008\/12\/image1.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/posts\/579"}],"collection":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/comments?post=579"}],"version-history":[{"count":0,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/posts\/579\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/media?parent=579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/categories?post=579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/tags?post=579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}