コード例 #1
0
        private static bool IsYesNo(M3U8TagInstance tag, M3U8ValueAttribute <string> attribute, bool defaultValue = false)
        {
            var attributeValueInstance = tag.Attribute(attribute);

            if (attributeValueInstance == null || string.IsNullOrWhiteSpace(attributeValueInstance.Value))
            {
                return(defaultValue);
            }
            return(0 == string.CompareOrdinal("YES", attributeValueInstance.Value.ToUpperInvariant()));
        }
コード例 #2
0
        private static void AddMedia(Uri playlist, M3U8TagInstance gt, IDictionary <string, MediaGroup> audioStreams)
        {
            var key       = gt.Attribute(ExtMediaSupport.AttrGroupId).Value;
            var uriString = gt.AttributeObject(ExtMediaSupport.AttrUri);
            Uri uri       = null;

            if (null != uriString)
            {
                uri = new Uri(playlist, new Uri(uriString, UriKind.RelativeOrAbsolute));
            }

            var str = gt.AttributeObject(ExtMediaSupport.AttrLanguage);
            var playlistSubStream1 = new PlaylistSubStream
            {
                Type         = gt.AttributeObject(ExtMediaSupport.AttrType),
                Name         = key,
                Playlist     = uri,
                IsAutoselect = IsYesNo(gt, ExtMediaSupport.AttrAutoselect),
                Language     = str?.Trim().ToLower()
            };

            var        playlistSubStream2 = playlistSubStream1;
            MediaGroup mediaGroup;

            if (!audioStreams.TryGetValue(key, out mediaGroup))
            {
                mediaGroup = new MediaGroup()
                {
                    Default = playlistSubStream2
                };
                audioStreams[key] = mediaGroup;
            }
            if (IsYesNo(gt, ExtMediaSupport.AttrDefault))
            {
                mediaGroup.Default = playlistSubStream2;
            }
            var index = gt.Attribute(ExtMediaSupport.AttrName).Value;

            mediaGroup.Streams[index] = playlistSubStream2;
        }