c# - Play User's Songs using Silverlight -


does have working (tested) example of code play audio file isolated storage. code have, doesn't throw exception or make sound, is:

        mediaelement me = new mediaelement();         me.autoplay = false;         isolatedstoragefile isf = isolatedstoragefile.getuserstoreforapplication();         me.setsource(isf.openfile("foo.wav", filemode.open));         me.play(); 

i've tried using number of different audio formats, encoded using expression, have same problem.

also, i'd quite example using file browser load song file stream, less important , isolated storage example converted.

i've checked, , if embed file in application, plays fine. problem want users able load own songs application, stored in , played isolated storage.

finally, example, i'd rather doing in c# code, rather xaml.

  1. you can't have play command in same method setsource command since file opened asynchronously. setting autoplay true (which defualt). ensure play it's loaded.

    mediaelement me = new mediaelement(); me.autoplay = true; isolatedstoragefile isf = isolatedstoragefile.getuserstoreforapplication(); me.setsource(isf.openfile("foo.wma", filemode.open)); 
  2. silvelright doesn't natively support wav files, play wav files need download http://code.msdn.microsoft.com/wavmss, use following code.

    mediaelement me = new mediaelement(); me.autoplay = true; isolatedstoragefile isf = isolatedstoragefile.getuserstoreforapplication(); me.setsource(new wavemediastreamsource(isf.openfile("foo.wav", filemode.open))); 

    although not ideal, can use file extensions detect when wav file being played , use second code sample in case.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -