"Select channel by index" nonfunction in TVGuide and everywhere for External Channels (1 Viewer)

Hesse

Portal Pro
August 8, 2006
110
0
MediaPortal Version: 0.2.0.4 and greater

There is a bug in the MP source code in the TVguide section that it is impossible to change channels by channel number even if the "select channel by index" is unchecked because this value is never used in the TV Guide source code! See the code for GUITvGuideBase.cs. The function ChangeChannelNr does not check the value of _byIndex because it is not even referenced in that class. Here is an updated version of the function ChangeChannelNr which should work and also include support for externalchannels which is so desperately needed:

Code:
    void ChangeChannelNr(int iChannelNr)
    {

      if (_byIndex) // Check if channel changing should be byIndex
      {
        // Channel change by index
        iChannelNr--;
      }
      else
      {
        // Change channel by using actual channel number
        int iCounter = 0;
        bool found = false;
        TVChannel chan;

        // Loop through complete channel list until match is found
        while (iCounter < _channelList.Count && found == false)
        {
          chan = (TVChannel)_channelList[iCounter];
          
          // Check if channel is an external channel
          if (chan.External == false)
          {
            //Not External Channel
            if (chan.Number == iChannelNr)
            {
              iChannelNr = iCounter;
              found = true;
            }
          }
          else
          {
            //External channel
            if (Int32.Parse(chan.ExternalTunerChannel) == iChannelNr)
            {
              iChannelNr = iCounter;
              found = true;
            }
          }
          iCounter++;  // Increment loop counter
        }
      }
          

      if (iChannelNr >= 0 && iChannelNr < _channelList.Count)
      {
        UnFocus();
        _channelOffset = 0;
        _cursorX = 0;

        // Last page adjust (To get a full page channel listing)
        if (iChannelNr > _channelList.Count - _channelCount + 1)
        {
          _channelOffset = _channelList.Count - _channelCount;
          iChannelNr = iChannelNr - _channelOffset;
        }

        while (iChannelNr >= _channelCount)
        {
          iChannelNr -= _channelCount;
          _channelOffset += _channelCount;
        }
        _cursorX = iChannelNr;

        Update(false);
        SetFocus();
      }
    }

Of course, the variable _byIndex needs to be added to the class, so I added it in the same way as it is in the GUITVHome.cs file.

Code:
#region variables
...snip
bool _byIndex = false;
...snip
#endregion

Then the LoadSettings() method should also include the _byIndex variable as:

Code:
    void LoadSettings()
    {
      using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.Get(Config.Dir.Config) + "MediaPortal.xml"))
      {
        _currentTvChannel = xmlreader.GetValueAsString("tvguide", "channel", String.Empty);
        _cursorX = xmlreader.GetValueAsInt("tvguide", "ypos", 0);
        _channelOffset = xmlreader.GetValueAsInt("tvguide", "yoffset", 0);
        _autoTurnOnTv = xmlreader.GetValueAsBool("mytv", "autoturnontv", false);
        _disableXMLTVImportOption = xmlreader.GetValueAsBool("plugins", "TV Movie Clickfinder", false);
        _byIndex = xmlreader.GetValueAsBool("mytv", "byindex", true);
      }
    }

Great, now we should be able to change channels by channel number correctly in the TV guide even with external channels if they are setup correctly (i.e externalchannel number field is populated).

Now, we have the problem of external channels not supported in the LiveTV. Here is the relevant code that fixes that problem as well. In the GUITVHome.cs file, the function ZapToChannelNumber should be

Code:
    public void ZapToChannelNumber( int channelNr, bool useZapDelay )
    {
      List<TVChannel> channels = CurrentGroup.TvChannels;

      if ( channelNr >= 0 )
      {
        bool found = false;
        int ChannelCnt = 0;
        TVChannel chan;
        while ( found == false && ChannelCnt < channels.Count )
        {
          chan = (TVChannel)channels[ChannelCnt];
          if (chan.External == false)
          {
            if (chan.Number == channelNr)
            {
              ZapToChannel(chan.Name, useZapDelay);
              found = true;
            }
          }
          else
          {
            if (Int32.Parse(chan.ExternalTunerChannel) == channelNr)
            {
              ZapToChannel(chan.Name, useZapDelay);
              found = true;
            }
          }
          ChannelCnt++;
        }
      }
    }

Now we have full support for changing channels by number and support for external channels.

There is also another problem. I have satellite TV in the US. The majority of the channels have three digits, but it is hardcoded in the OnKeyCode function in the GUITvGuideBase.cs file to only accept 2 digits. Can this be made a variable and put in the TV configuration section? I will post separately if necessary.

Developers, please look at this code and let me and everyone else know what you think. I believe this should fix all of the problems that us U.S. users are having with changing channel by actual channel numbers and also support external channels for a STB.

Jesse
 

Hesse

Portal Pro
August 8, 2006
110
0
For those that are interested in testing this change, I compiled the code. You need to be running a recent SVN. Please backup your file before overwriting.

Note that in this file I hardcoded the channel number input to 3 digits and increased the delay time for us satellite users. The delay probably needs to be a bit longer even still.

Jesse
 

jawbroken

Portal Pro
August 13, 2005
706
0
Home Country
Afghanistan Afghanistan
Have you added this to the patch queue so it can be incorporated into the MediaPortal source code after it has been reviewed?
 

Hesse

Portal Pro
August 8, 2006
110
0
jawbroken

No, I didn't do that. It sounds like mPod has added it for me. Thanks for that mPod. For future reference, since I'm a newbie at this, how would I do that? Is there information in the wiki on that?
 

natrlhy

Retired Team Member
  • Premium Supporter
  • August 2, 2006
    324
    0
    Bay Area, CA
    Home Country
    United States of America United States of America
    I see that the SVN changelog indicates:

    MediaPortal MyTV
    23/09/2006 [11:27h] mPod added: "Select channel by index" did not work in TVGuide and everywhere for External Channels (thanks to Hesse)

    Does this indicate that this passed the test teams tests? I'm running mediaportal-svn--09-24-2006--02-04-rev10448.exe and I will be trying this out tonight. It has been a troublesome to change channels on my external STB (DirecTV). Have others tried the newer SVN's and confirmed that this fix works?

    Thanks Hesse and mPod!
     

    Hesse

    Portal Pro
    August 8, 2006
    110
    0
    I see that the SVN changelog indicates:

    MediaPortal MyTV
    23/09/2006 [11:27h] mPod added: "Select channel by index" did not work in TVGuide and everywhere for External Channels (thanks to Hesse)

    Does this indicate that this passed the test teams tests? I'm running mediaportal-svn--09-24-2006--02-04-rev10448.exe and I will be trying this out tonight. It has been a troublesome to change channels on my external STB (DirecTV). Have others tried the newer SVN's and confirmed that this fix works?

    Thanks Hesse and mPod!

    You'll find that its hardcoded right now into MP to only use 2 digits for entering channels with an 800ms timeout, so it won't work for us DirecTV users. In the attached file in the first page of this thread, I updated it so that it accepts 3 digits with a 2 s timeout. You can use that for now until the source gets updated to allow an option to set the number of digits (see the MPChannelUpdater thread).
     

    Hesse

    Portal Pro
    August 8, 2006
    110
    0
    I just noticed a small flaw in the code that I submitted. When changing channels in the TV guide, if you enter a channel number that doesn't exist, then it will drop through the for loop since it won't match a channel and then simply change channel by index which was the previous behaviour.

    I think what we'd ideally want is that if a channel isn't found, it would go to the nearest match. So if the channels that exist are 495 501 502 503 504 and we entered 500, it would change to 501 to get us to the right section of the guide. I think this is how DirectTV works by default. I'll have to look over that section of code again to see the best way to implement that.

    For now it will work fine if you enter the exact channel number.
     

    Users who are viewing this thread

    Top Bottom