NullReferenceException on LoadPlaylistAsync()

Sep 28, 2009 at 2:05 PM
Edited Sep 28, 2009 at 5:11 PM

I feel like I’m getting close to having an implementation of this working, but the application crashes when I call LoadPlaylistAsync() in my javascript.

(1) Here is the method I’m using to start streaming in javascript:

function pluginLoaded(sender, args) {
        
var slCtl = sender.getHost();

var mcProxy;

if (document.MulticastProxyNS) {

            mcProxy = document.MulticastProxyNS;

      } else {

            mcProxy = document.MulticastProxyProxy;
}

slCtl.Content.Bridge.PlaylistLoaded = function() {
slCtl.Content.Bridge.StartStreaming(mcProxy);

};

// CRASHES HERE with nullreferenceexception, but the link is valid...
slCtl.Content.Bridge.LoadPlaylistAsync("http://iptv-web/03.nsc");

}

 (2) To start out, here is what I have in the Application_Startup method in App.xaml.cs:

HtmlPage.RegisterScriptableObject("Bridge", new Starlight.Lib.MulticastController());

(3) And the following code was added to my silverlight CS file:

private MulticastController Bridge;

public MainPage()
{

      // Required to initialize variables

      	InitializeComponent();

	Bridge = new MulticastController();

	Bridge.PlaylistLoaded += new EventHandler(Bridge_PlaylistLoaded);
}

void Bridge_PlaylistLoaded(object sender, EventArgs e)
{}

private void MyApp_OnLoad(object sender, System.Windows.RoutedEventArgs e)
{
	try
	{
		Bridge.AttachMediaElement(MediaElement_01);
         		Bridge.LoadPlaylistAsync("http://iptv-web/03.nsc");
	}
      	catch (Exception exc)
      {
	         MessageBox.Show(exc.Message);
      }
}

I’m just wondering if there is anything obvious that I am doing wrong?  Maybe in the MyApp_OnLoad() handler? Also, I feel like I shouldn't have to call LoadPlaylistAsync() twice - once in C# and the other in javascript - but I

couldn't decipher the documentation well enough to understand how the method should be invoked...?

 

Coordinator
Sep 29, 2009 at 6:41 PM

I'm not sure there's enough info here to fully resolve the issue.  If you could post the stacktrace on the nullreference you are getting that would be helpful.

A couple of notes:

1.)  You only need to call LoadPlaylistAsync once.  Call it either from your MyApp_OnLoad, or in the javascript pluginLoaded method.  The reason it is done in javascript in the sample is that it is not hardcoded into the app, and can be changed just by changing the HTML of the page.

2.)  You need to pass a URL to an ASX file, not an NSC to LoadPlaylistAsync.  You could also pass something like "asx:<ASX><ENTRY><REF href="http://iptv-web/03.nsc"/></ENTRY></ASX>" to specify the ASX inline instead of fetching it from a web server.

3.)  You should probably handle the PlaylistLoaded event either in javascript or in the C#., not both.

Sep 29, 2009 at 8:35 PM

Thanks...yeah, my resulting error is:

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Browser.ManagedObjectInfo.Invoke(ManagedObject obj, InvokeType invokeType, String memberName, ScriptParam[] args)
   at System.Windows.Browser.ManagedObject.Invoke(InvokeType invokeType, Int32 memberID, ScriptParam[] args)
   at System.Windows.Hosting.ScriptingInterface.InvokeScriptableMember(ManagedObject obj, InvokeType invokeType, Int32 memberID, ScriptParam[] args, ScriptParam& pResult)
   at System.Windows.Hosting.ManagedHost.InvokeScriptableMember(IntPtr pHandle, Int32 nMemberID, Int32 nInvokeType, Int32 nArgCount, ScriptParam[] pArgs, ScriptParam& pResult, ExceptionInfo& pExcepInfo)

I changed my javascript to the following - the alert('streaming') message never pops up, so I'm guessing that for some reason, the PlaylistLoaded event never fires:

     function onPluginLoaded(sender, args) {
            try {
                var slCtl = sender.getHost();

                var mcProxy = document.MulticastProxy;

                slCtl.Content.Bridge.PlaylistLoaded = function() {
                    alert('streaming...');
                    slCtl.Content.Bridge.StartStreaming(mcProxy);
                };

                slCtl.Content.Bridge.LoadPlaylistAsync("asx:<ASX><ENTRY><REF href='http://iptv-web/03.nsc'/></ENTRY></ASX>");

And my C# code was changed to the following:

	    private MulticastController Bridge;

		public MainPage()
		{
			// Required to initialize variables
			InitializeComponent();
            Bridge = new MulticastController();
        }

	    private void SenateIPTV_OnLoad(object sender, System.Windows.RoutedEventArgs e)
		{
	        try
	        {
                Bridge.AttachMediaElement(MediaElement_01);
	        }
	        catch (Exception exc)
	        {
	            MessageBox.Show(exc.Message);
	        }
		}

 

Hope that helps?

Sep 30, 2009 at 2:29 AM

Success!!...unfortunately, I wasn't able to fire off the PlaylistLoaded event in the JavaScript (for some reason?), so I had to do that in the C#:

	public partial class MainPage : UserControl
	{
	    private MulticastController Bridge;

		public MainPage()
		{
			// Required to initialize variables
			InitializeComponent();
            		Bridge = new MulticastController();
        		}

	    	private void MyIPTV_OnLoad(object sender, RoutedEventArgs e)
		{
	        		try
	        		{
                			Bridge.PlaylistLoaded += new EventHandler(Bridge_PlaylistLoaded);
	            		Bridge.AttachMediaElement(MediaElement_01);
                			Bridge.LoadPlaylistAsync("asx:<ASX><ENTRY><REF href='http://iptv-web/03.nsc'/></ENTRY></ASX>");
	        		}
	        		catch (Exception exc)
	        		{
	            		MessageBox.Show(exc.Message);
	        		}
		}

        		void Bridge_PlaylistLoaded(object sender, EventArgs e)
        		{
			// "MulticastProxy" is the ID of the multicast <Object>
           		 Bridge.StartStreaming((ScriptObject)HtmlPage.Document.GetElementById("MulticastProxy"));
       		 }
	}