使用Silverlight Stream 轻松托管部署你silverlight应用程序

来源:互联网 发布:淘宝pv uv是什么意思 编辑:程序博客网 时间:2024/05/19 12:38
 使用Silverlight Stream 轻松托管部署你silverlight应用程序

当开发者或设计师完成Silverlight一个应用程序后,最关心的无疑是如何将我的Silverlight应用程序第一时间发布在网络上,http://silverlight.live.com为开发者和设计师提供了一个Silverlight应用程序的托管部署平台,它是微软官方提供的免费Silverlight应用程序托管平台,它具有以下特点:

  • Silverlight Streaming默认提供10G存储空间
  • 每个文件上传增大到了约100M,满足开发者上传较大的多媒体文件
  • 视频流传输速度为1400kbps,满足高清多媒体视频流畅回放
  • 简单方便的Silverlight应用程序发布流程

使用Silverlight Streaming平台托管你的Silverlight应用程序之前,你需要将Silverlight编译后的XAP文件和一个manifest.xml文件,打包成一个zip压缩包,manifest.xml(清单)文件中包括Silverlight应用程序运行时的基本信息,例如:源文件名、版本、尺寸等,下面代码是一个最简单的清单文件。

<SilverlightApp>
  <
version>2.0</version
>
  <
source>myapp.xap</source
>
  <
width>400</width
>
  <
height>300</height
>
  <
background>white</background
>
  <
isWindowless>false</isWindowless
>
</
SilverlightApp>

代码中声明了应用程序的版本为2.0,源文件名称为myapp.xap,宽400高300,背景为白色,不使用Windowless支持的Silverlight应用程序,Silverlight Streaming就是根据这些信息来生成应用程序的部署代码,下面表中列中的就是清单文件支持全部的内容。

Element Description

source

The filename of the main XAML file or the application's XAP file, relative to the directory structure of the ZIP file.

version

The minimum version of the Silverlight runtime required to run your Silverlight application. For example, if you set the value of this element to 1.0, the user must have version 1.0 or greater of the Silverlight runtime to view it. If you leave this value blank, the user will be forced to download the latest Silverlight runtime to run your application.

width

The width of the Silverlight application, expressed in browser units (pixels) or as a percentage value.

height

The height of the Silverlight application, expressed in browser units (pixels) or as a percentage value.

background

A string value specifying the background color for the application frame after the application has loaded and while it is initializing. It may be a named color value or an 8-bit or 16-bit color value, with or without alpha transparency.

backgroundImage

A string value specifying a background image for the application frame after the application has loaded and while it is initializing.

isWindowless

Specifies whether to display the Silverlight control in windowless mode. True or False.

framerate

The maximum number of frames to render per second.

enableHtmlAccess

Specifies whether the hosted content in the Silverlight control has access to the browser Document Object Model (DOM). True or False.

inPlaceInstallPrompt

Determines whether to display an install prompt if the detected version of Silverlight is out of date.

onLoad

The name of a JavaScript function to run when the application has finished loading and the content has rendered. Note that this functionality differs from that of the Silverlight onLoad event, which fires after the application has finished loading but before the content has rendered.

onError

The name of a JavaScript error handling function.

jsOrder

Specifies the order in which JavaScript files will be loaded. Each file should be listed with the relative path name as it appears in the ZIP file. File names and paths are case-sensitive. Any JavaScript files not mentioned will be loaded in an unspecified order after the listed files.

 

然后你需要在官网上获取你的Silverlight Streaming的Account ID和Account Key,如图所示,点击GetFree会提示你创建一个Windows Live帐号,如果你已经注册过Windows Live ID的话,你就可以直接使用你的Live帐号进行绑定,如果你没有ID,可以根据提示注册一个Windows Live ID即可,输入用户ID和密码,点击Sign in即完成了Silverlight Streaming帐号的绑定,并显示出你的Silverlight Streaming个人帐号信息。

 

接下来就可以上传你的Silverlight应用程序了,点击左侧的Manage Applications(管理应用程序),会列出你已经上传过的Silverlight应用程序,点击Upload an application(上传一个Silverlight应用程序),输入Silverlight应用程序名称,再选择你的Silverlight应用程序包并提交上传(就是你压缩后的XAP和清单文件的zip包),这样你的Silverlight应用程序就被托管到Silverlight Streaming服务器上了,值得注意的是,如果你的压缩包中没有包含清单文件,上传后会提示在网页上手工来创建。

 

完成Silverlight应用程序的托管,最后就是如何将你的应用程序在你需要的位置呈现出来,Silverlight Streaming为开发者提供了两种表现方式,分别是使用内嵌的方式和使用Live控件的方式。

 

内嵌方式:内嵌方式与称为iframe方式,这种方式部署起来十分简单,你只需要把整个iframe内的代码连同iframe标签一起复制并插入到你网页内容的任意位置,你的Silverlight应用程序便会在页面加载后完整呈现出来,代码如下。

<iframe src="http://silverlight.services.live.com/invoke/78099/myapp/iframe.html" scrolling="no" frameborder="0" style="width:400px; height:300px"></iframe>

 

Live控件:使用Live控件方式部署分为三个步骤,首先要为页面的<html>标签加入xmlns特性,然后在<Header>标签中引用live.js和controls.js,最后在需要的位置加入一个devlive控件,代码如下。

<html xmlns:devlive="http://dev.live.com">
<
head>
    <
title>My Silverlight Application</title>
<script type="text/javascript" src="https://controls.services.live.com/scripts/base/v0.3/live.js"></script>
<script type="text/javascript" src="https://controls.services.live.com/scripts/base/v0.3/controls.js"></script>

</
head>
<
body>
<devlive:slscontrol silverlightVersion="2.0" src="/78099/myapp/">

</devlive:slscontrol>
</
body>
</
html>

 

image

 

使用Live控件方式部署所有良好的安装体验,如图所示,但是你必须对Silverlight所在的整个页面有修改的权限,很显然,第一种内嵌方式方式部署起来更为灵活方便,所以推荐使用内嵌方式在页面插入Silverlight应用程序的。

 

 

原创粉丝点击