Hi
I have developed a Silverlight Application with out of Browser support on visual studio 2013. I tried to pass init params from the html page, but the App.xaml parses the url with null value. So the OOB App cannot play a video. The code in html page is:
<param name="initParams" value="m1=http://192.168.1.23:1935/vod/mp4:a.mp4/Manifest, m2=customdata" />
The App.xaml.cs code for Application Startup is,:
private void Application_Startup(object sender, StartupEventArgs e) { IDictionary<String, String> initParams; if (e.InitParams != null) { // reading all initparams and adding it to global resources dictionary foreach (var data in e.InitParams) { this.Resources.Add(data.Key, data.Value); } } if (Application.Current.IsRunningOutOfBrowser) { using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream( "initParams.txt", System.IO.FileMode.OpenOrCreate, file)) { // The serializer requires a reference to System.Runtime.Serialization.dll. DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Dictionary<String, String>)); initParams = (Dictionary<String, String>)serializer.ReadObject(stream); } } // Otherwise, save initParams to isolated storage. else { initParams = e.InitParams; using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream( "initParams.txt", System.IO.FileMode.Create, file)) { DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<string, string>)); serializer.WriteObject(stream, initParams); } } MessageBox.Show(String.Concat(e.InitParams)); }
The MainPage.xaml.cs for the application is:
public partial class MainPage : UserControl { string _URL = ""; string _CD = ""; public MainPage() { InitializeComponent(); this.Loaded += new RoutedEventHandler(Page_Loaded); _URL = GetParameterValueFromKey("m1"); _CD = GetParameterValueFromKey("m2"); // SmoothPlayer.SmoothStreamingSource = new Uri(_URL); SmoothPlayer.LicenseAcquirer.ChallengeCustomData = _CD; } private string GetParameterValueFromKey(string key) { if (Application.Current.Resources[key] != null) { return Application.Current.Resources[key].ToString(); } else { //MessageBox.Show(_URL); return string.Empty; } } void Page_Loaded(object sender, RoutedEventArgs e) { _URL = GetParameterValueFromKey("m1"); if (_URL == null) { string value = App.Current.Resources["m1"].ToString(); SmoothPlayer.SmoothStreamingSource = new Uri(_URL); } else { MessageBox.Show("No code"); } }
I am a newbie to this Silverlight development. And I developed upto here almost. Please help me out here. The problem i found in debugging is that the url passed in the html page comes empty in the App.xaml. The URL value is null. I tested it with conditional statements and displaying the url in each step. Seems that the App.xaml.cs and MainPage.xaml.cs are passing null value for URL.
Please respond asap. Thank you in Advance.