Tag Archives: time line

Stream You Tube Video, in Google Glass Time Line Card, using Mirror API(C#.net)

Ok guys today we will see how we can stream a Youtube video inside a google glass timeline card.  First you need to add reference to the “YoutubeExtractor” namespace. You can get it from the nuget if you dont have it.

using YoutubeExtractor;

Now add the youtube video url to atring(The url you got when you clicked the share button not the page url).
Resolve the url and get the links for the available videos.
Select the video you wanted to stream and get the stream url.

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;

Now create the timeline card and add the menu item

TimelineItem yotubeVideo = new TimelineItem()
{
Text = "Youtube Video",
BundleId = "8081",
MenuItems = new List<MenuItem>() { { new MenuItem() { Action = "DELETE" } } },
Notification = new NotificationConfig() { Level = "DEFAULT" }
};

Create a stream using the link we got, create a http request, buffer it and insert the card mentionng the video type.

String videoLink = vLink;

if (!String.IsNullOrEmpty(videoLink))
{
Stream stream = null;
if (videoLink.StartsWith("/"))
{
stream = new StreamReader(controller.Server.MapPath(videoLink)).BaseStream;
}
else
{
HttpWebRequest request = WebRequest.Create(videoLink) 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(yotubeVideo, stream, "video/mp4").Upload();

Now the stream will work like a charm

Advertisements

Adding a time line card using Mirror API, that can make call from Google Glass (C#.net)

To call a person you need contact details of a person so we will create a contact first.

Contact Amalan = new Contact();
Amalan.PhoneNumber = "+940711111111";

Now create a Timeline card and add call function on the menu item of the  card. When create the timeline card add the contact we created as the Creator

TimelineItem contactNumber = new TimelineItem()
{

Text = "Call Amalan",
BundleId = "8081",
Creator = Amalan,
MenuItems = new List<MenuItem>() {
new MenuItem() {Action = "VOICE_CALL"},
new MenuItem() {Action = "DELETE"}},
Notification = new NotificationConfig() { Level = "DEFAULT" },

};

Now we will insert the card that we created

controller.Service.Timeline.Insert(contactNumber).Fetch();

That’s it now you can make the call using the timeline card. Don’t forget to pair your phone with the GLASS

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