Selecting a video track using javascript

Sep 15, 2011 at 9:17 PM



I'd like to control the SMF player using java script. I use it for smooth streaming.

I 'm currently able to Play/Pause and change playlist as described in and in

But is there a way with the standart SMF player to select a particular video track, or to restrict to only one video track? The goal is to be able to select a particular video track for tests purposes.

I found some methods that could do the work (class StreamInfo in namespace Microsoft.Web.Media.SmoothStreaming, méthods  SelectTracks and RestrickTracks, property AvailableTracks) but as I'm new to .net api and silverlight, I don't see how to use them and if it is possible to use them in an html page with javascript.





Sep 20, 2011 at 11:01 AM
Edited Sep 20, 2011 at 11:11 AM


In source code, it exists a example (testjs.html in Microsoft.SilverlightMediaFramework.Test.Web project) for create a playlist and select a particular play list item, chapter index or seconds.

Hope this helps you.

Javascript code:


var Player = null;

function onPlayerReady(player) {
        Player = player;

function SetPlaylistIndex(index) {

function SetChapterIndex(index) {

function SeekToPosition(seconds) {

function NextPlaylistItem() {

function PreviousPlaylistItem() {

function NextChapter() {

function PreviousChapter() {

Sep 23, 2011 at 8:50 AM

Hello carmenpilar, and thanks you for your reply.


But, in fact, this is not really what I want to do :

1. What I'm currently able to do :

* doing play / pause

* loading another stream : (I put the code - it could help others)

function doLoadAnotherAdaptiveLiveStream(stream) {
    var NewPlaylistItem = Player.CreatePlaylistItem(stream, '', 'Title', 'Description');
    NewPlaylistItem.DeliveryMethod = 'AdaptiveStreaming';
    var NewPlaylist = Player.CreatePlaylist();

So notice I'm playing with adapative streaming. I'm only playing with live streams - with the function above, I can load another livestreaming without reloading silverlight. This is better because the change happends more quickly than when recreating the silverlight object etc ... in the web page.


2. What I'm currently not able to do is to select with javascript another biterate (It is called a track if I have correctly understood the net api).

Why I want to manualy select a bitrate instead of letting the player selects the best?

=> Because this player is used for tests purposes: It will be used in a local network, near from the server, and I like to be able to select a particular track to check with my eyes if it looks correct or not.

Note this is possible to do this with the HDS protocol used by adobe with flash using the following javascript method (I use the standart OSMF player (for them who are interested,  - look in the jsdemo.js file included when downloading the osmf player) ):

* obj.switchDynamicStreamIndex() to change the current profile

* obj.getNumDynamicStreams to get the number of available profile in the stream

I think it would be great if such functionnality were embedded with the standart smf player. I think it is not currently the case and I do not really want to dig into the sfm code to create another player that export this api to javascript.

Am I wrong ?

Does someone know how to simply select a track (= a particular bitrate) ?

Is it planned to export more functionnalities in the JavaScript bridge class ?

Thanks in advance,