Insert Video in, Google Glass Time Line Cards, using Mirror API(C#.net)

private static String InsertVideo(MainController controller)
{

TimelineItem critical = new TimelineItem()
{

//Text = "Third Card",
BundleId = "346",
//IsBundleCover=true,
//Html = "<article class=\"photo\">\n  <img src=\"http://www.youtube.com/watch?v=suz446-BOHg\" width=\"100%\" height=\"100%\">\n  <div class=\"photo-overlay\"/>\n  <section>\n    <p class=\"text-auto-size\">Third Card</p>\n  </section>\n</article>",
//Attachments = new List<Attachment>() {new Attachment(){ContentUrl="http://www.youtube.com/watch?v=suz446-BOHg"}},
//MenuItems = menu,
Notification = new NotificationConfig() { Level = "DEFAULT" },
MenuItems = new List<MenuItem>()
{
new MenuItem() {Action = "NAVIGATE"},
new MenuItem() {Action = "DELETE"},
new MenuItem() {Action = "SHARE"},
}
// Locaton = location.Latitude
//bundleId = 10001;
};

String mediaLink = "your video link as text here";

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;
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();
//controller.Service.Timeline.Update

}

return "A timeline item has been inserted.";

}

Credit goes to Sanath Nandasiri

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s