问题
I'm not familiar with Silverlight (5) but think I'm close to getting what I'm trying to do working. Grateful for any help.
Basically, I need to pass a dynamically generated smooth stream URI into the player and set "Media Source" correctly.
Steps I'm taking..
Client invocation, a single key-value pair..
<param name="InitParams" value="mediaurl=http://playready.directtaps.net/smoothstreaming/TTLSS720VC1/To_The_Limit_720.ism/Manifest" />
MainPage.xaml..
<!--Media:PlaylistItem DeliveryMethod="AdaptiveStreaming" MediaSource="mPlayer" /-->
App.xaml.cs
public Dictionary<string, string> PageData = new Dictionary<string, string>();
private void Application_Startup(object sender, StartupEventArgs e)
{
var paramValues = e.InitParams;
foreach (var param in paramValues)
{
this.PageData.Add(param.Key, param.Value);
}
this.RootVisual = new MainPage();
}
MainPage.xaml.cs..
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
App currentApp = (App)Application.Current;
string uriString = currentApp.PageData["mediaurl"];
MessageBox.Show(uriString);
Microsoft.SilverlightMediaFramework.Core.Media.PlaylistItem item = new Microsoft.SilverlightMediaFramework.Core.Media.PlaylistItem();
item.MediaSource = new Uri(uriString, UriKind.Absolute);
item.DeliveryMethod =
Microsoft.SilverlightMediaFramework.Plugins.Primitives.DeliveryMethods.AdaptiveStreaming;
//Add PlaylistItem to the Media playlist
Microsoft.SilverlightMediaFramework.Core.SMFPlayer SMFPlayer = new Microsoft.SilverlightMediaFramework.Core.SMFPlayer();
SMFPlayer.Playlist.Add(item);
SMFPlayer.Play();
}
}
Visual Studio 2015 Compiler doesn't complain with MainPage.xaml.cs
but it doesn't work.
The Silverlight player plays static URIs fine, but not URIs passed in InitParam
.
回答1:
You say that setting the url manually like this works...
<Media:PlaylistItem DeliveryMethod="AdaptiveStreaming" MediaSource="http://playready.directtaps.net/smoothstreaming/TTLSS720VC1/To_The_Limit_720.ism/Manifest" />
in that case then you need to update view so you can make control accessible by name from code behind (IDE).
<Media:PlaylistItem x:Name="playListItem" DeliveryMethod="AdaptiveStreaming"/>
and then in the code behind, reference that control
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
App currentApp = (App)Application.Current;
string uriString = currentApp.PageData["mediaurl"];
MessageBox.Show(uriString);
//reference item by name
Microsoft.SilverlightMediaFramework.Core.Media.PlaylistItem item = this.playListItem;
item.MediaSource = new Uri(uriString, UriKind.Absolute);
//...other code
}
}
The other example from the link I sent you did it like this.
In MainPage.xaml
<Grid x:Name="LayoutRoot" Background="White"
xmlns:smf="http://schemas.microsoft.com/smf/2010/xaml/player">
<smf:SMFPlayer HorizontalAlignment="Stretch" Margin="0"
x:Name="sMFPlayer" VerticalAlignment="Stretch" />
</Grid>
In MainPage.xaml.cs
using Microsoft.SilverlightMediaFramework.Core.Media;
using Microsoft.SilverlightMediaFramework.Plugins.Primitives;
//...
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
App currentApp = (App)Application.Current;
string uriString = currentApp.PageData["mediaurl"];
var item = new PlaylistItem();
item.MediaSource = new Uri(uriString, UriKind.Absolute);
item.DeliveryMethod = DeliveryMethods.AdaptiveStreaming;
//Add PlaylistItem to the Media playlist
sMFPlayer.Playlist.Add(item);
sMFPlayer.Play();
}
}
来源:https://stackoverflow.com/questions/36646767/silverlight-5-dynamic-stream-uri-setting