c# - Soundplayer for compiled application -
how can hardcode code in order pull .wav file project?
as should put .wav file?
http://i58.tinypic.com/npmjnn.jpg
the code using is:
private void timer2_tick(object sender, eventargs e) { soundplayer simplesound = new soundplayer(@"c:\windows\media\dj.wav"); simplesound.play(); } i want path @"c:\windows\media\dj.wav" content folder... when deploy application computer comes it....
use getmanifestresourcestream.
var path = "myapplicationnamespace.content.dj.wav"; var assembly = assembly.getexecutingassembly(); using( var soundstream = assembly.getmanifestresourcestream( path ) ) using( var soundplayer = new soundplayer( soundstream ) ) { soundplayer.play(); } the string passed getmanifestresourcestream must qualified application's root namespace , directory tree wave file resides in.
you need set build action wave file embedded resource in properties window.
Comments
Post a Comment