来自http url的视频缩略图

时间:2015-09-18 04:16:24

标签: c# windows-phone

是否可以通过随机网址创建视频缩略图? 我有一些视频链接,我想从该视频制作缩略图并将缩略图保存在本地存储上。如果有可能的方法吗?

1 个答案:

答案 0 :(得分:1)

以下是youtube视频的解决方案: -

public string GetThumbnailsUrl(string url)// this url is your youtube video url
{
    string imgurl = "";
    if (url != "")
    {
        if (!url.ToLower().Contains("embed/"))//if not an embed URL
        {
            string v = url;
            if (url.Contains("?"))
            {
                v = v.Substring(v.LastIndexOf("v=") + 2);
                if (v.Contains("&"))
                    v = v.Substring(0, v.LastIndexOf("&"));
            }
            else
            {
                v = v.Substring(v.LastIndexOf("v/") + 2);
            }
            int i = 0;
            try
            {
                i = Convert.ToInt32(ConfigurationManager.AppSettings["ImageSize"].Trim());//ImageSize contains the size of image.... the value is like 0,1,2,3.....
            }
            catch { i = 0; }

            imgurl = "http://img.youtube.com/vi/" + v + "/" + i + ".jpg";
        }
        else//For embed URL
        {
            string[] sep = new string[1] { "embed/" };
            string[] ss = url.Split(sep, StringSplitOptions.None);
            string key = ss[ss.Length - 1];
            int i = 0;
            try
            {
                i = Convert.ToInt32(ConfigurationManager.AppSettings["ImageSize"].Trim());
            }
            catch { i = 0; }
            imgurl = "http://img.youtube.com/vi/" + key + "/" + i + ".jpg";
        }


    }
    return imgurl;
}