Mar 21

Playing Local Resources:

With the current CTP you will need to set up the local media file as "Content", not as "Resource" to make it work. Note that this is different from SL3 this is a current limitation because in the CTP release playback from a Stream object is not yet supported.

 

 

So create your phone project in blend..

 

image

 

Create your solution then add in the video file to your solution as an existing item (in this case wildlife.wmv)

 

image

 

Next: drag it onto the design surface in blend and resize it to fit your project and Windows Phone Screen size..

 

image

 

Next hit save all from the file menu to save out all of the project changes..

NEXT and this is the magic part..

Open the project from the Visual Studio Express 2010 for Windows Phone which should have installed with the phone CTP..

image

 

You can also do this while still in Expression Blend 4..

 

image

 

Right Click on the Solution and from the pop-up menu select edit in visual studio to open the project in visual studio..

 

Next go to the solution explorer:

 

image

 

Now select the file wildlife.wmv

go down to the properties window

 

image

 

make sure the BUILD ACTION property  is set to “CONTENT”  not “RESOURCE”

Save the project and close it and now you may return to Expression Blend and work..

Your media element xaml may look like this in your project

<MediaElement Source="wildlife.wmv" Width="200" Height="200" AutoPlay="True" />

Note the current SL 4 BUILD will corrupt your xaml by adding a "/" to Source="/Wildlife.wmv" be sure you remove that in the xaml SOURCE code. it's not enough to just correct it in the blend UI.. The Phone Device doesn't handle backslashes properly in this build because it's not a PC..

 

UPDATE: Playing Audio Using XNA..

You can USE XNA in Silverlight for Windows Phone 7 to play audio in silverlight..

Here's how to: (thanks to Pete Blois for this information)

1.       Convert your sound effect to WAV format (not sure of bitrate requirements, but XNA docs have this info)

2.       Add the sound file to your project either as either

a.       Content in which case you’ll load it via:

Stream stream = TitleContainer.OpenStream(soundFileName);

 

b.      Embedded Resource and load it via:

Stream stream = Application.GetManifestResourceStream(soundUri )

 

                (For phone development it's better to try to keep most resources as content rather than in the assembly because re-deploying large assemblies is somewhat slow

 

3.       Add a reference to Microsoft.Xna.Framework (should appear in the references dialog in VS)

4.       Create the sound effect:

SoundEffect effect = SoundEffect.FromStream(stream);