1

我需要使用 .Net 将 YouTube 视频链接添加到我的 Glassware TimeLine 卡。我已经将它添加为流,但它有更多时间上传和播放。

    Service.Timeline.Insert(timelineItem, stream, "video/mp4").Upload();

我可以将此添加为 YouTube 链接吗?

谢谢

4

1 回答 1

2

可以在时间线卡中流式传输 youtube 视频,这是 C#.Net 代码。使用这个命名空间“YoutubeExtractor”。我正在做的是从标准 youtube url 解析流 url,然后从中选择视频 url 并流式传输。这对我来说很好。获取 youtube 视频 url 时,获取选择共享后出现的链接。

 private static String InsertItem5(MainController controller)
    {

        string link = "http://youtu.be/9uYKISlL7Vg";
        IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);
        VideoInfo video = videoInfos.First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360);
        String vLink = video.DownloadUrl;


        TimelineItem critical = new TimelineItem()
        {

            Text = "Menu Card",
            BundleId = "666",
            Notification = new NotificationConfig() { Level = "DEFAULT" },
            MenuItems = new List<MenuItem>()
                                     {
                                         new MenuItem() {Action = "DELETE"},
                                     }

        };

        String mediaLink = vLink;

        if (!String.IsNullOrEmpty(mediaLink))
        {
            Stream stream = null;
            if (mediaLink.StartsWith("/"))
            {
                stream = new StreamReader(controller.Server.MapPath(mediaLink)).BaseStream;
            }
            else
            {
                HttpWebRequest request = WebRequest.Create(mediaLink) as HttpWebRequest;

                request.UseDefaultCredentials = false;


                HttpWebResponse response = request.GetResponse() as HttpWebResponse;

                byte[] b = null;
                using (Stream streamFromWeb = response.GetResponseStream())
                using (MemoryStream ms = new MemoryStream())
                {
                    int count = 0;
                    do
                    {
                        byte[] buf = new byte[1024];
                        count = streamFromWeb.Read(buf, 0, 1024);
                        ms.Write(buf, 0, count);
                    } while (streamFromWeb.CanRead && count > 0);
                    b = ms.ToArray();

                    stream = new MemoryStream(b);
                }
            }
            controller.Service.Timeline.Insert(critical, stream, "video/mp4").Upload();
        }
        else
        {
            controller.Service.Timeline.Insert(critical).Fetch();
        }

参考: http: //pathofacoder.com/2013/10/16/stream-you-tube-video-in-google-glass-time-line-card-using-mirror-apic-net/

于 2013-10-16T06:16:34.537 回答