开发者

Silverlight player: how to embed

I am trying to create javascript that will embed a silverlight video but when I put it in webpage, it doesnt work.

<div id="silverlightControlHost"></div>
&开发者_运维百科lt;script type="text/javascript">
    Silverlight.createObject(
        "myvideo.3gp",  //video 
        document.getElementById('silverlightControlHost'),  // parent
        "slPlugin",  // id for generated Silverlight object
        {
            width: "400", height: "100", background: "#CCCCCC"
        }, // property values of the silverlight object
        {  }, // event handlers (optional)
        "param1=value1,param2=value2", //extra params (optional)
        "context"    // context (optional)
    );
    </script>


We do this at NimbusHD; for a sample embedded player go to www.nimbushd.com > See a Video.

I wouldn't use the Silverlight.createObject() method... just write out your <object> tag directly.

<script type="text/javascript" src="http://play.nimbushd.com/Silverlight.js"></script>
    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
                appSource = sender.getHost().Source;
            }

            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
                return;
            }

            var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

            errMsg += "Code: " + iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " + args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }
    </script>
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="640" height="480" style="z-index: -1;">
          <param name="source" value="/path/to/my/silverlightApp.xap"/>
          <param name="onError" value="onSilverlightError" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="4.0.50826.0" />
          <param name="autoUpgrade" value="true" />
          <param name="Windowless" value="true" />
          <param name="initParams" value="" />
          <div>You don't have Silverlight installed</div>
        </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜