示例#1
0
        private void SetPreferredSubtitle_intern(ref BaseStreamInfoHandler subtitleStreams)
        {
            if (subtitleStreams == null)
            {
                return;
            }

            VideoSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <VideoSettings>() ?? new VideoSettings();

            // first try to find a stream by it's exact LCID.
            StreamInfo streamInfo = subtitleStreams.FindStream(settings.PreferredSubtitleLanguage) ?? subtitleStreams.FindSimilarStream(settings.PreferredSubtitleStreamName);

            if (streamInfo == null || !settings.EnableMpcSubtitlesEngine)
            {
                // auto-activate forced subtitles
                StreamInfo forced = subtitleStreams.FindForcedStream();
                if (forced != null)
                {
                    subtitleStreams.EnableStream(forced.Name);
                }
                else
                {
                    StreamInfo noSubtitleStream = subtitleStreams.FindSimilarStream(GetNoSubsName());
                    if (noSubtitleStream != null)
                    {
                        subtitleStreams.EnableStream(noSubtitleStream.Name);
                    }
                }
            }
            else
            {
                subtitleStreams.EnableStream(streamInfo.Name);
            }
        }
示例#2
0
        private void SetPreferedAudio_intern(ref BaseStreamInfoHandler audioStreams, bool useFirstAsDefault)
        {
            if (audioStreams == null || audioStreams.Count == 0)
            {
                return;
            }

            VideoSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <VideoSettings>();

            // When multiple streams are available, we select the stream by channel count preference (PreferMultiChannelAudio).
            Predicate <StreamInfo> channelCountPreference;

            if (settings.PreferMultiChannelAudio)
            {
                channelCountPreference = (a => a.ChannelCount > 2); // Prefer more then stereo (usually 6ch)
            }
            else
            {
                channelCountPreference = (a => a.ChannelCount <= 2); // Stereo or even mono
            }
            // Check if there are multiple audio streams for the PreferredAudioLanguage.
            int preferredAudioLCID = settings.PreferredAudioLanguage;

            List <StreamInfo> streamsForLCID = audioStreams.ToList().FindAll(a => a.LCID == preferredAudioLCID && a.LCID != 0);
            int count = streamsForLCID.Count;

            if (count > 0)
            {
                // If we have only one choice, select this stream.
                if (count == 1)
                {
                    audioStreams.EnableStream(streamsForLCID[0].Name);
                    return;
                }

                StreamInfo bestChannelStream = streamsForLCID.Find(channelCountPreference);
                if (bestChannelStream != null)
                {
                    audioStreams.EnableStream(bestChannelStream.Name);
                    return;
                }
            }

            // If we did not find matching languages by LCID no try to find them by name.
            StreamInfo streamInfo = null;

            if (preferredAudioLCID != 0)
            {
                try
                {
                    CultureInfo ci           = new CultureInfo(preferredAudioLCID);
                    string      languagePart = ci.EnglishName.Substring(0, ci.EnglishName.IndexOf("(") - 1);
                    streamInfo = audioStreams.FindSimilarStream(languagePart);
                }
                catch { }
            }

            // Still no matching languages? Then select the first that matches channelCountPreference.
            if (streamInfo == null)
            {
                streamInfo = audioStreams.ToList().Find(channelCountPreference);
            }

            if (streamInfo != null)
            {
                audioStreams.EnableStream(streamInfo.Name);
            }
            else
            if (useFirstAsDefault)
            {
                audioStreams.EnableStream(audioStreams[0].Name);
            }
        }