Jump to content

GetChannelList in c#


Recommended Posts

Can anyone provide me with a short code snippet(pref in c#) that shows available channels?

 

I have rather limited experience developing in c#, and now i'm stuck.

 

I've tried following to get a channel list:

object obj;
DVBViewer.ChannelManager.GetChannelList(out obj);
Console.WriteLine(obj.ToString());

 

The list seems empty. DVBViewer is running and everything seems fine.

Edited by pär
Link to comment
did u connect to DVBViewer before ?

 

yes, using:

DVBViewer = (DVBViewer)System.Runtime.InteropServices.Marshal.GetActiveObject("DVBViewerServer.DVBViewer");

 

and DVBViewer is running.

 

Apparently, DVBViewer.ChannelManager has a property named "Item"(according to the docs). But my instance of DVBViewer won't recognize this property. It does, however, find the property "Count".

Link to comment

first i'm not sure that u should use out argument for the parameter (out implies that parameter already contains a value i think)

second, chanlist is a 2 dimension array so the tostring method may not work: did u try to browse the object

Link to comment
first i'm not sure that u should use out argument for the parameter (out implies that parameter already contains a value i think)

second, chanlist is a 2 dimension array so the tostring method may not work: did u try to browse the object

 

 

Oh.

Well, how do i browse it? :wacko:

Thanks for your help.

Link to comment
  • 1 year later...

I used the following to get the channel list:

 

 

IDVBViewer dvbServer = (IDVBViewer)Marshal.GetActiveObject("DVBViewerServer.DVBViewer");

 

IChannelCollection chnCol = dvbServer.ChannelManager;

 

for (int k = 0; k < chnCol.Count; k++)

{

System.Console.WriteLine(chnCol[k].Name);

}

Link to comment

			IDVBViewer m_DvbViewer = null;

		try
		{
			// Try and get the running instance, a COMException is thrown if the class name is not known
			m_DvbViewer = (IDVBViewer)Marshal.GetActiveObject("DVBViewerServer.DVBViewer");
		}
		catch (COMException)
		{
			if (MessageBox.Show("DVBViewer is currently not running.\r\nDo you wish to start it?", "Start DVBViewer", MessageBoxButtons.YesNo) == DialogResult.Yes)
			{
				// DVBViewer isn't running, so start it
				m_DvbViewer = new DVBViewer();
			}
		}
		finally
		{
			if (m_DvbViewer != null)
			{
				object[,] oDvbChannelArray = null;
				object oDvbChannelList = new object();
				m_DvbViewer.ChannelManager.GetChannelList(out oDvbChannelList);
				oDvbChannelArray = (object[,])oDvbChannelList;
			}
		}

You could declare the size of the channel array saving the cast if you wanted to.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...