System.Serialization异常===> Vimeo视频无法在Xamarin.forms应用程序的IOS / Android上播放

时间:2019-07-16 18:23:29

标签: xamarin xamarin.forms vimeo vimeo-api

enter image description here突然没有加载Vimeo上托管的视频。 序列化部分后失败。无法理解,因为这突然开始发生。

try
{
    Match vimeoMatch = VimeoVideoRegex.Match(VideoId);

    if (vimeoMatch.Success)
        VideoId = vimeoMatch.Groups[1].Value;

    var videoInfoUrl = $"https://player.vimeo.com/video/{VideoId}/config";

    using (var client = new HttpClient())
    {
        var videoPageContent = client.GetStringAsync(videoInfoUrl).Result;
        var videoPageBytes = Encoding.UTF8.GetBytes(videoPageContent);

        using (var stream = new MemoryStream(videoPageBytes))
        {
            var serializer = new DataContractJsonSerializer(typeof(VimeoVideo));
            var metaData = (VimeoVideo)serializer.ReadObject(stream);
            var files = metaData.request.files.progressive;

            // Exact match
            var url = files.OrderByDescending(s => s.width).Select(s => s.url).FirstOrDefault();

            Debug.WriteLine($"Stream URL: {url}");
            return VideoSource.FromUri(url);
        }
    }
}

0 个答案:

没有答案