Exemplo n.º 1
0
        private static void ProcessSubtitle(
            this AVPlayerViewController controller,
            CMTime time)
        {
            NSString text = NSString.Empty;

            NSArray payload = controller.Payload();

            for (nuint i = 0; i < payload.Count; ++i)
            {
                NSDictionary item = payload.GetItem <NSDictionary>(i);
                NSNumber     from = item.ObjectForKey(new NSString("from")) as NSNumber;
                NSNumber     to   = item.ObjectForKey(new NSString("to")) as NSNumber;
                if (time.Seconds >= from.FloatValue &&
                    time.Seconds < to.FloatValue)
                {
                    text = item.ObjectForKey(new NSString("text")) as NSString;
                    break;
                }
            }

            UILabel subtitleLabel = controller.SubtitleLabel();

            subtitleLabel.Text = text;
            var attributes = new UIStringAttributes();

            attributes.Font = subtitleLabel.Font;
            CGRect rect = text.GetBoundingRect(
                new CGSize(subtitleLabel.Bounds.Width, nfloat.MaxValue),
                NSStringDrawingOptions.UsesLineFragmentOrigin,
                attributes, null
                );

            controller.SubtitleConstranint().Constant = rect.Size.Height + 5;
        }