Пример #1
0
        public SubtitleSelector(ISubtitleStream dvbStreams, SubtitleRenderer subRender, TeletextSubtitleDecoder subDecoder)
        {
            Log.Debug("SubtitleSelector ctor");
            if (subRender == null)
            {
                throw new Exception("Nullpointer input not allowed ( SubtitleRenderer)");
            }
            else
            {
                this.dvbStreams = dvbStreams;
                this.subRender  = subRender;
            }

            // load preferences
            using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Config, "MediaPortal.xml")))
            {
                preferedLanguages = new List <string>();
                string languages = reader.GetValueAsString("tvservice", "preferredsublanguages", "");
                Log.Debug("SubtitleSelector: sublangs entry content: " + languages);
                StringTokenizer st = new StringTokenizer(languages, ";");
                while (st.HasMore)
                {
                    string lang = st.NextToken();
                    if (lang.Length != 3)
                    {
                        Log.Warn("Language {0} is not in the correct format!", lang);
                    }
                    else
                    {
                        preferedLanguages.Add(lang);
                        Log.Info("Prefered language {0} is {1}", preferedLanguages.Count, lang);
                    }
                }
            }

            pageEntries = new Dictionary <int, TeletextPageEntry>();

            bitmapSubtitleCache = new List <SubtitleOption>();

            lock (syncLock)
            {
                if (subDecoder != null)
                {
                    subDecoder.SetPageInfoCallback(new MediaPortal.Player.Subtitles.TeletextSubtitleDecoder.PageInfoCallback(OnPageInfo));
                }

                if (dvbStreams != null)
                {
                    RetrieveBitmapSubtitles();
                    subStreamCallback = new SubtitleStreamEventCallback(OnSubtitleReset);
                    IntPtr pSubStreamCallback = Marshal.GetFunctionPointerForDelegate(subStreamCallback);
                    Log.Debug("Calling SetSubtitleStreamEventCallback");
                    dvbStreams.SetSubtitleResetCallback(pSubStreamCallback);
                }

                if (preferedLanguages.Count > 0)
                {
                    autoSelectOption          = new SubtitleOption();
                    autoSelectOption.language = "None";
                    autoSelectOption.isAuto   = true;
                    autoSelectOption.type     = SubtitleType.None;

                    SetOption(0); // the autoselect mode will have index 0 (ugly)
                }
            }
            Log.Debug("End SubtitleSelector ctor");
        }
Пример #2
0
    public SubtitleSelector(ISubtitleStream dvbStreams, SubtitleRenderer subRender, TeletextSubtitleDecoder subDecoder)
    {
      Log.Debug("SubtitleSelector ctor");
      if (subRender == null)
      {
        throw new Exception("Nullpointer input not allowed ( SubtitleRenderer)");
      }
      else
      {
        this.dvbStreams = dvbStreams;
        this.subRender = subRender;
      }

      // load preferences
      using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Config, "MediaPortal.xml")))
      {
        preferedLanguages = new List<string>();
        string languages = reader.GetValueAsString("tvservice", "preferredsublanguages", "");
        Log.Debug("SubtitleSelector: sublangs entry content: " + languages);
        StringTokenizer st = new StringTokenizer(languages, ";");
        while (st.HasMore)
        {
          string lang = st.NextToken();
          if (lang.Length != 3)
          {
            Log.Warn("Language {0} is not in the correct format!", lang);
          }
          else
          {
            preferedLanguages.Add(lang);
            Log.Info("Prefered language {0} is {1}", preferedLanguages.Count, lang);
          }
        }
      }

      pageEntries = new Dictionary<int, TeletextPageEntry>();

      bitmapSubtitleCache = new List<SubtitleOption>();

      lock (syncLock)
      {
        if (subDecoder != null)
        {
          subDecoder.SetPageInfoCallback(new MediaPortal.Player.Subtitles.TeletextSubtitleDecoder.PageInfoCallback(OnPageInfo));
        }

        if (dvbStreams != null)
        {
          RetrieveBitmapSubtitles();
          subStreamCallback = new SubtitleStreamEventCallback(OnSubtitleReset);
          IntPtr pSubStreamCallback = Marshal.GetFunctionPointerForDelegate(subStreamCallback);
          Log.Debug("Calling SetSubtitleStreamEventCallback");
          dvbStreams.SetSubtitleResetCallback(pSubStreamCallback);
        }

        if (preferedLanguages.Count > 0)
        {
          autoSelectOption = new SubtitleOption();
          autoSelectOption.language = "None";
          autoSelectOption.isAuto = true;
          autoSelectOption.type = SubtitleType.None;

          SetOption(0); // the autoselect mode will have index 0 (ugly)
        }
      }
      Log.Debug("End SubtitleSelector ctor");
    }