Windows Phone7开发之 多媒体控件
webphp
13年前
<p style="text-indent:0px;margin:5px auto;">多媒体控件,就是所谓的音视频控件、图像控件,在Phone7中,也有许多与silverlight的不同之处。</p> <p style="text-indent:0px;margin:5px auto;">一.Image:图像控件,<span style="line-height:19px;font-family:NSimSun;color:blue;font-size:9.5pt;"><span style="font:7pt 'Times New Roman';"> </span></span><span style="line-height:19px;font-family:宋体;">用来显示本地或网络图像。这个控件只支持几个图像格式,如果要显示其他的图像格式就需要自已编解码了。</span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;font-family:宋体;"><span style="line-height:19px;font-family:NSimSun;color:blue;font-size:9.5pt;"><span style="line-height:19px;font-family:NSimSun;color:blue;"><</span><span style="line-height:19px;font-family:NSimSun;color:#a31515;">Image</span><span style="line-height:19px;font-family:NSimSun;"> <span style="line-height:19px;color:red;"> x</span><span style="line-height:19px;color:blue;">:</span><span style="line-height:19px;color:red;">Name</span><span style="line-height:19px;color:blue;">="image"</span><span style="line-height:19px;color:red;"> Source</span><span style="line-height:19px;color:blue;">="Chrysanthemum.jpg"</span><span style="line-height:19px;color:red;"> Height</span><span style="line-height:19px;color:blue;">="200"</span><span style="line-height:19px;color:red;"> Width</span><span style="line-height:19px;color:blue;">="200"</span> <span style="line-height:19px;color:blue;"> /></span></span></span></span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;font-family:宋体;"><span style="line-height:19px;font-family:NSimSun;color:blue;font-size:9.5pt;"><span style="line-height:19px;font-family:宋体;">在</span>XAML<span style="line-height:19px;font-family:宋体;">中可以在</span>Source<span style="line-height:19px;font-family:宋体;">属性中设置图片的相对路径,这时图片一定要是</span>content <span style="line-height:19px;font-family:宋体;">并</span>copy<span style="line-height:19px;font-family:宋体;">到</span>xap<span style="line-height:19px;font-family:宋体;">包中,否则无法显示。</span></span></span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;font-family:宋体;"><span style="line-height:19px;font-family:NSimSun;color:blue;font-size:9.5pt;"><span style="line-height:19px;font-family:宋体;">也可以在代码中动载加载图片:</span></span></span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;font-family:宋体;"><span style="line-height:19px;font-family:NSimSun;color:blue;font-size:9.5pt;"><span style="line-height:19px;font-family:NSimSun;">image.Source = <span style="line-height:19px;color:blue;">new</span> <span style="line-height:19px;color:#2b91af;">BitmapImage</span>(<span style="line-height:19px;color:blue;">new</span> <span style="line-height:19px;color:#2b91af;">Uri</span>(<span style="line-height:19px;color:#a31515;">"Chrysanthemum.jpg"</span>, <span style="line-height:19px;color:#2b91af;">UriKind</span>.Relative));</span></span></span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;font-family:宋体;"><span style="line-height:19px;font-family:NSimSun;color:blue;font-size:9.5pt;"><span style="line-height:19px;font-family:宋体;">也可以加载网上图片,只要用绝对地址就可以了:</span></span></span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;font-family:宋体;"><span style="line-height:19px;font-family:NSimSun;color:blue;font-size:9.5pt;"><span style="line-height:19px;font-family:NSimSun;">image1.Source = <span style="line-height:19px;color:blue;">new</span> <span style="line-height:19px;color:#2b91af;">BitmapImage</span>(<span style="line-height:19px;color:blue;">new</span> <span style="line-height:19px;color:#2b91af;">Uri</span>(<span style="line-height:19px;color:#a31515;">"http://ts3.cn.mm.bing.net/images/thumbnail.aspx?q=191518215482&id=bec03c581dba154b8d310e9f262f3711&url=http%3a%2f%2fimg6.uutuu.com%2fdata6%2fa%2fph%2flarge%2f091026%2f7963e66b2cc1c1f00f5e2fb24d11fc8f.jpg"</span>, <span style="line-height:19px;color:#2b91af;">UriKind</span>.Absolute));</span></span></span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;"><br /> </span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;"><br /> </span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;">二.MediaElement:</span><span style="line-height:19px;font-family:宋体;">多媒体播放控件。可以播放本地和网络上的多媒体,支持</span>mms:<span style="line-height:19px;font-family:宋体;">、</span>rtspt:<span style="line-height:19px;font-family:宋体;">、</span>rtsp:<span style="line-height:19px;font-family:宋体;">流媒体协议。这个控件相对</span>windows mobile<span style="line-height:19px;font-family:宋体;">有了很大的不同,</span>mobile<span style="line-height:19px;font-family:宋体;">上的这个控件就是一个完整的播放器,但是现在的控件却只是一个可以播放多媒体的窗口已而,所有的控制都需要自已来实现,甚至全屏播放。</span></p> <p style="text-indent:0px;margin:5px auto;" align="left"><span style="line-height:19px;font-family:NSimSun;color:blue;"><</span><span style="line-height:19px;font-family:NSimSun;color:#a31515;">MediaElement</span><span style="line-height:19px;font-family:NSimSun;color:red;"> Grid.Row</span><span style="line-height:19px;font-family:NSimSun;color:blue;">="1"</span><span style="line-height:19px;font-family:NSimSun;color:red;"> Height</span><span style="line-height:19px;font-family:NSimSun;color:blue;">="649"</span><span style="line-height:19px;font-family:NSimSun;color:red;"> HorizontalAlignment</span><span style="line-height:19px;font-family:NSimSun;color:blue;">="Left"</span><span style="line-height:19px;font-family:NSimSun;color:red;"> Name</span><span style="line-height:19px;font-family:NSimSun;color:blue;">="mediaElement1"</span><span style="line-height:19px;font-family:NSimSun;color:red;">VerticalAlignment</span><span style="line-height:19px;font-family:NSimSun;color:blue;">="Top"</span><span style="line-height:19px;font-family:NSimSun;color:red;"> Width</span><span style="line-height:19px;font-family:NSimSun;color:blue;">="480"</span><span style="line-height:19px;font-family:NSimSun;color:red;"> IsMuted</span><span style="line-height:19px;font-family:NSimSun;color:blue;">="False"</span><span style="line-height:19px;font-family:NSimSun;color:red;"> Stretch</span><span style="line-height:19px;font-family:NSimSun;color:blue;">="UniformToFill"</span><span style="line-height:19px;font-family:NSimSun;color:red;"> Source</span><span style="line-height:19px;font-family:NSimSun;color:blue;">="Medias/Wildlife.wmv"/></span></p> <p style="text-indent:0px;margin:5px auto;">Source<span style="line-height:19px;font-family:宋体;">:设置要播放的多媒体地址(可以是本地的,也可以网络上的)。如果要动态播放文件,可以在程序中设置。</span></p> <p style="text-indent:0px;margin:5px auto;" align="left"><span style="line-height:19px;font-family:NSimSun;">mediaElement1.Source = <span style="line-height:19px;color:blue;">new</span> <span style="line-height:19px;color:#2b91af;">Uri</span>(<span style="line-height:19px;color:#a31515;">"http://mschannel9.vo.msecnd.net/o9/mix/09/wmv/key01.wmv"</span>, <span style="line-height:19px;color:#2b91af;">UriKind</span>.Absolute);</span></p> <p style="text-indent:0px;margin:5px auto;" align="left"><span style="line-height:19px;font-family:NSimSun;">mediaElement1.Source = <span style="line-height:19px;color:blue;">new</span> <span style="line-height:19px;color:#2b91af;">Uri</span>(<span style="line-height:19px;color:#a31515;">"Medias/Wildlife.wmv"</span>, <span style="line-height:19px;color:#2b91af;">UriKind</span>.Relative);</span></p> <p style="text-indent:0px;margin:5px auto;"> </p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;font-family:NSimSun;color:#a31515;">IsMuted</span><span style="line-height:19px;font-family:宋体;color:#a31515;">:是否静音。</span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;font-family:NSimSun;color:#a31515;">Stretch</span><span style="line-height:19px;font-family:宋体;color:#a31515;">:用来设置视频画面在控件中填充方式,很像</span><span style="line-height:19px;font-family:NSimSun;color:#a31515;">Image</span><span style="line-height:19px;font-family:宋体;color:#a31515;">控件。</span></p> <p style="text-indent:0px;margin:5px auto;"><span style="line-height:19px;font-family:宋体;color:#a31515;"><span style="color:#a31515;"><span style="font-family:新宋体;">AutoPlay</span><span style="line-height:19px;font-family:宋体;color:#a31515;">:是否自动播放。</span></span></span></p>