Silverlight Streaming for video assets only


Posted on February 6, 2008
Filed Under:   1.0 Javascript, streaming, video |

The Silverlight Streaming service is great for hosting your applications but what if you just want to host your assets there, particularly your heavy bandwidth assets like videos? Well the process is a bit like uploading an application (covered in the previous post) but with a few differences. You still need to create a manifest.xml file but this time since you have no code files to upload you will just reference a dummy.xaml file. You dont need to include this phantom xaml file in your zip but you do have to reference it in the manifest like so…

<SilverlightApp>  
   <source>dummy.xaml</source>
</SilverlightApp>

So just add the above snippet to your “manifest.xml” file, and include it in your zip with your video(s) file and upload to the Silverlight Streaming service.

Now for the tricky parts. You need to make a modification to your code to reference not your local copy of silverlight.js but the remote version supplied by the service, something like http://agappdom.net/h/silverlight.js

Another important change is in your createSilverlight function:

function createSilverlight() {  

   Silverlight.createHostedObjectEx({  

        source: "interface.xaml",  

        parentElement: document.getElementById("Wrapper_MultipleVideos"),  

        id: "SilverlightControl",  

        properties: {  

            width: "940",  

            height: "600",  

            background:"#bb5619",  

            isWindowless: "false",  

            framerate:"30",  

            version: "1.0"  

        },  

        events: {  

        },  

        initParams:"streaming:/48598/MultipleVideos/"  

    });  

}

Two things to note here: 1) use the Silverlight.createHostedObjectEx function call and 2) the additional initParams property.

The initParams property takes a string as input, and should point to your AccountID and Application’s Name listed on the Silverlight Streaming service site, in this case it’s “MultipleVideos”.

What happens here is that the service will convert the string specified into a proper URL. This URL is NOT permanent and will change so you cant just write it down and hard code it into your functions or xaml. Therefore you need to programmatically set the source of your MediaElement.

So for example you could do something like this in your initial start up function of your app (or in the Loaded event call for your main Canvas)

function mainCanvasLoaded(s) { 
   plugin = s.getHost()
   main=s.findName("mainCanvas")
   vid1=main.findName("videoElement1")
   vid2=main.findName("videoElement2")  

   //dynamic URL assignment happens here
   vid1.source=plugin.initParams+"/my_video1.wmv"
   vid2.source=plugin.initParams+"/my_video2.wmv"
}

If you want to upload and reference multiple videos under different application name’s you would need to tweak the initParams property like so to be a comma separated list:

initParams:"streaming:/48598/MondaysVideo/, streaming:/48598/ThursdaysVideo/"

And then in your video source assignment code you could handle that with a split(”,”) call like this:

   urlArray=plugin.initParams.split(",")
   vid1_url=urlArray[0]
   vid2_url=urlArray[1]

Official info on the subject can be found here at this MSDN article, but I didn’t find it too helpful.

Comments

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

1 Comment so far
  1. Mike Snows Silverlight Blog May 5, 2008 5:16 pm

    Silverlight Resources…

    The following is my list of Silverlight Resources including blogs, tutorials and more. If you know of…

Recently


Categories


Archives


Resources