So many of the controls are "static", are "dumb", today, do you have any interest in the study, can be "vivid" and simple operation of the control? If so, please come with me.MediaElement play multimedia files.
First of all, a grand introduction of MediaElement, why should it be grand? Because it's simple, really, you'll play it, but, mediaelement powerful, it can play audio and video as long as the supported formats are on the line.
To set the playback of audio or video files, you only need to set the Source property, it is actually a URI, if you want to play media files in your project, you have to add the media file to your project, the build operation is set as a resource, do not I say, will be.
You will certainly ask, can play the network URI point to the media file? Oh, you'll find out if you try.
Gossip does not pull, start doing exercises, first bring a 3gp or MP4 file, you can find one yourself, of course, other formats are also available, hehe, as long as the support on the line, because we see the effect in the simulator, so finally with some commonly used format, simulator not all media files can support, Please refer to the SDK documentation for details.
MediaElement is very easy to use, I would like to say a few of its commonly used properties, I believe you can understand the two under the study.
1, Source: Just said, is you want to play media files;
2, AutoPlay: Whether automatically play, Ah, this estimate you more than I understand;
3, Balance: Stereo volume ratio of the left and right channel, is a balance value, from 1 to 1,0 in the middle, so is the default value;
4, Stretch: Like the image control, how to stretch, or maintain the aspect ratio;
5, Volume: volume, 0-1 in range, default 0.5.
OK, here's a look at the layout of the first exercise.
To illustrate, the graphics on each button are drawn on my hand, the content property is set to the path object to draw and fill the paths, in order to be concise, I use the path marking method, not urgent, I will introduce the article later.
Continue to write the code in the background, more simple, just a few methods of invocation.
Use MediaElement and VideoBrush together.
This is our second exercise, VideoBrush is also a painting brush, but it is very special, it does not have a monochrome, no gradient color, it is used to fill the surface of the object with video, such as the background brush of the elements, foreground paint brush and so on.
VideoBrush as long as the SourceName property value is set to MediaElement name can, that is, VideoBrush source is from the MediaElement object, you can both use simultaneously, of course, If you only want to use VideoBrush, set MediaElement's visibility property to collapsed.
One thing to note, though, is that MediaElement and VideoBrush are used in your pages at the same time, but inside, they actually only read the data once, so the number of media files referenced depends only on the MediaElement class, No matter how many videobrush you use on the page, there is no impact on performance, before we said resources, I believe you remember, resources is to improve the reusability rate, do not have to create resources every time, otherwise it will greatly impair performance, the files in the project, said, you just set the build operation as a resource, It can be reused without saying that I assign a new instance every time I add a reference, which does not require that the resource instance be created only once and can be repeated for multiple references.
If you don't use resources, imagine how horrible it would be if a MP3 has 2000 bytes, and if you use it every time you need to make a new one in memory, if I'm using 100 of these objects at once, that's 100 * 2000 = 200000 bytes, so the memory is exhausted. But what if it's a resource? As long as it is created, has been the same reference, memory only allocates 2000 bytes for it, no matter you have 1000 in the same place in reference to it, pointing to the same piece of memory area, ha, do not know this explanation, enough to understand it?
OK, just blow here, here we practice another example, show Hello on TextBlock, but I hope the foreground of this textblock is not to fill with the color, but to fill it with video, so this text looks very vivid, yes, Did you think of the filter layer in Flash? But now you can easily implement it through the VideoBrush class.
Remember the transformation and three-dimensional perspective that you said in the first two lectures? You might as well try your own, knowledge is through the "snowball" way to accumulate 1.1 points, so, I strongly recommend you to change the above code, the above two sections of the content and the content of this section to see if you can make a beautiful effect out.
Windows Phone Development (20): When MediaElement and VideoBrush work together,