SupportedInitParams

Dec 6, 2010 at 6:04 PM
Edited Dec 6, 2010 at 6:09 PM

I would like to use InitParams to determine my media source with the SMFplayer and not use the PlayList feature.

I'm trying to use InitParameters="MediaUrl={0}" where the actual Url is provided by a CMS.

I am also trying to use Michael Scherotter's version of the player that was extended with a download progress bar.

http://blogs.msdn.com/b/synergist/archive/2010/10/23/download-progress-bar-for-silverlight-media-framework-player.aspx?wa=wsignin1.0

In the SMF API reference, under SupportedInitParams, it seems like MediaUrl would be an option to send my movie's Url.

Is there anything else required to use InitParameters?

I have just pulled out the SMFPlayer.Playlist nodes from the MainPage.xaml and was hoping I could pass a MediaUrl to my player.

Thanks in advance for any help.... I am also new to Silverlight, I am working my way through everything on this.

 

 

 

Dec 7, 2010 at 7:43 PM

The MediaUrl InitParameter will work if your xap is simply the player, but if you are adding functionality and creating your own xap you might want to write it yourself. You should still be using playlists. In your case you just have a playlist of one. You do not need to show the playlist tab on the player but behind the scenes your video should still be a PlaylistItem.

You can use any Init Parameters you want. In your HTML you can specify any init param name/value pairs like this:

<object id="SilverlightPlugin" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
    <param name="source" value="myPlugin.xap" />
    <param name="onError" value="OnSilverlightError" />
    <param name="background" value="Black" />
    <param name="minRuntimeVersion" value="1.2.3" />
    <param name="autoUpgrade" value="true" />
    <param name="initParams" value="MediaUri=http://mydomain/myVideo.mp4" />
    ...
</object>

Then you can read those initParams in you App.xaml.cs

private void ApplicationStartup(object sender, StartupEventArgs e)
{
    string mediaUri = e.InitParams["MediaUri"];
    ...
}

Now that you have the data you want on the Silverlight side you need to determine how you are going to get that data to your player. Depending on your design decisions that can vary.

If you are using MVVM:
You might create a new PlayerViewModel class passing in the MediaUri. The constructor would create a new PlaylistItem with your MediaUri. Then you can data bind your view model's PlaylistItems property to the Player's Playlist collection.

app.xaml.cs

 

private void ApplicationStartup(object sender, StartupEventArgs e)
{
    string mediaUri = e.InitParams["MediaUri"];
    PlayerPage page = new PlayerPage();
    page.LayoutRoot.DataContext = new PlayerViewModel(mediaUri);

    RootVisual = page;
}

PlayerViewModel.cs

public ObservableCollection<PlaylistItem> PlaylistItems { get; set; }
private Uri _mediaUri;

public PlayerViewModel() {}

public PlayerViewModel(string mediaUri)
{
    _mediaUri = new Uri(mediaUri);
    PlaylistItems = new ObservableCollection<PlaylistItem>
    {
        new PlaylistItem { MediaSource = _mediaUri }
    };
}

PlayerPage.xaml

<Grid x:Name="LayoutRoot">
    <smf:SMFPlayer Playlist="{Binding PlaylistItems}" PlaylistVisibility="Disabled"/>
</Grid>
Dec 8, 2010 at 1:42 PM

Thanks so much for posting this, swhook52! I've got the code added to my Silverlight App now, but it seems like I'm missing a namespace reference for PlayerPage on my App.xaml.cs. Could you help with that? Google didn't get me too far....

I found a reference to that existing in System.Web.UI.SilverlightControls, but that seems to be from Silverlight 2.

Dec 8, 2010 at 1:46 PM

PlayerPage.xaml was just a name I made up that would hold your SMFPlayer control. For you, that could be your MainPage.xaml or whatever page name you may have. If you have a clean solution that just has a MainPage and App files, just replace PlayerPage with MainPage in my examples.

I think most people use code behind instead of the MVVM example I gave. MVVM is a little bit more complex to understand, but you'll be better off if you get it going like that.

Dec 8, 2010 at 4:41 PM

Thanks again... got it going now and was able to now swap it in place of the player that Telerik includes with Sitefinity (their own Silverlight Media Player, but no control over the look which is very blue and without captions)... now to see if I can get some captions working!

Jan 13, 2012 at 11:36 AM

Can you send the source code running.. This is exactly as I need but is confused.

Thank you