How to play an attachment video from the timeline item - google-mirror-api

I want to insert a timelineitem with video attachment and if user selects a specific menu item, glass to play the video. I'm doing all from .net app like this, please correct me, if i'm doing wrong.
TimelineItem item = new TimelineItem()
item.MenuItems.Insert(0, new MenuItem(){Action="what is the action to use?";...});
request = Service.Timeline.Insert(item, attachment, contentType);
request.Upload();
I would like to know, do i need a menu item, if yes, what is the action i should use?
Currently i'm sending the video attachment, but there is no way to play the video.
Any help is greatly appreciated.

You don't need to specify any menuItems but your timeline item should not contain html content.
Make sure that your video is of a supported format: once it's inserted, and Glass has synced and fully downloaded the attached video, it should start playing right when you land on the item in your timeline.

This works using the QuickStart project for Java (mirror-java-starter-demo):
https://github.com/googleglass/mirror-quickstart-java
Replace the lines near line 119 in MainServlet.java with this:
URL url = new URL(req.getParameter("imageUrl"));
String contentType = req.getParameter("contentType");
url = new URL("http://localhost:8888/static/videos/video.mp4");
contentType = "video/mp4";
byte[] b = ByteStreams.toByteArray(url.openStream());
int i = b.length;
InputStream temp = url.openStream();
MirrorClient.insertTimelineItem(credential, timelineItem, contentType, temp);
Then run the project and click the "A Picture" button to upload a video from a new folder inside static called videos called video.mp4. I used a 10 second clip I recorded with glass (6.30 MB).
Note that when running with App Engine 1.76 on a windows machine I got this error when uploading, but changing to 1.80 made this issue go away:
Here is Windows metadata about the video that might be useful:
Depending on your network connection it might take a little bit for the video to show in your timeline, but mine plays.

Related

Loading image from storage

I have an image that I loaded by using URLImage class. Here is the code:
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(getWidth()/2, getWidth()/2 , 0xF92D2D), true);
Image originImg = URLImage.createToStorage(placeholder, imgFileName, photo_url);
To my understanding, this image is being saved into Storage with createToStorage() method. However, next time when I am loading this form, I don't want to download the image again, I want to take it from the Storage, because its faster.
So what I did, I added check :
if (Storage.getInstance().exists(imgFileName)) {
// Take the image from the Storage
originImg = Image.createImage(Storage.getInstance().createInputStream(imgFileName));
} else {
// Load the image with URLImage class.
}
However, it seems like my file is never saved into the Storage. What can be wrong?
You don't need to do that. URLImage seamlessly loads the file from storage if the file is already there. You can open the network monitor and see if a request is made to the URL for this specific image.
I'm not sure why the Storage.getInstance().exists(imgFileName) method would fail. I assume the image name is different in the different execution or something of that sort. You can see that images are created in your .cn1 directory.

Opening blob in new window failing if file larger than 1MB or so

I am building a react project where a user needs to be able to preview a document that has been uploaded. I have the file stored in a blob file in a variable called 'upload', and I use the following code to display it in a new tab when the user clicks on the preview button:
var newWIndow;
if (upload.includes("data:application/pdf"))
newWIndow = "<iframe width='100%' height='100%' src='" + upload + "'></iframe>"
else
newWIndow = "<img width='100%' src='" + upload + "'></img>";
var x = window.open();
x.document.open();
x.document.write(newWIndow);
x.document.close();
The uploads are limited to image or pdf files, and works great, except when the file size goes over 1MB. In that case, it simply opens a blank page:
THe entire blob file is too large to post here, but I thought that giving an idea of what it looks like might help someone spot what I am doing wrong, so here is a snippet:
data:application/pdf;base64,JVBERi0xLjQNJeLjz9MNCjEgMCBvYmoNPDwvTWV0YWRhdGEgMiAwIFIvUGFnZXMgMyAwIFI
Does anyone perhaps have any advice for me? Is there a better way to open the uploaded document? Is there a way to get around the size issue? Any advice would be greatly appreciated.
I was mistaken, I was not using a blob object but a binary Base64 one. The new question, as well as the solution, is posted in this post.

JSON data post to the URL opened in CefSharp browser with example

I am opening a webpage in the cefsharp browser and trying to send a set of JSON data to my website's .aspx page along with query string. While the query string is not an issue but sending the JSON data to the same URL is what I am trying to fix. Earlier I was using Window's native WebBrowser control's Navigate method where I was passing the URL along with query string as well as a byte array. But, I don't find any such method to post the data. Various discussion and posts regarding the same don't have a clear example. Can you provide a sample code/example to show how to achieve that? Here is the code I've been using:
ChromiumWebBrowser browser = new ChromiumWebBrowser();
browser.Address = "https://webhook.site";
browser.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
browser.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
browser.RequestHandler = this;
browser.IsBrowserInitializedChanged += (sender, args) =>
{
if (browser.IsBrowserInitialized)
{
browser.LoadUrlWithPostData("https://webhook.site/#/cba9d04b-01ff-40ef-b223-0917d127ecbe/6ce82e34-28df-4900-88ef-c932a446c6b0/1", Encoding.UTF8.GetBytes("test=123&data=456"));
}
};

How to switch from camera recording to on screen recording using RecordRTC API?

I am a newbie to Audio/Video Recording. The script works well for my cam and audio recorder. However, I would like to know how to implement it similar to the Extension available so that I can record a tab and all the audio involved. Thanks in advance. Currently using Ver.5.4.0
Here is an open-sourced chrome-extension that supports both tab, screen and any opened app's screen recording:
https://github.com/muaz-khan/Chrome-Extensions/tree/master/screen-recording
You can use tabCapture API to capture MediaStream object; now you can record the resulting stream using MediaRecorder API or RecordRTC.
RecordRTC can record following kind of streams:
Stream captured from a webcam or microphone
Stream captured using tabCapture API
Stream captured using desktopCapture API
Stream captured from <canvas> or <video> elements using captureStream API
Streams generated by WebAudio API
e.g.
var capturedStream = videoElement.captureStream();
var recorder = RecordRTC(videoElement.captureStream(), {
type: 'video'
});
Or:
var recorder = RecordRTC(tabCaptureStream, {
type: 'video'
});
Simply make sure that you're getting the MediaStream object from above API; and now you can use RecordRTC to record that stream.
Regarding "replacing video track with secondary camera track or screen track", you can use addTrack, removeTrack as well as replaceTrack methods. However I'm not sure if MediaRecorder API can record replaced track:
// using Firefox
theStreamYouAreRecording.replaceTrack( screenTrack );
// using Chrome or Firefox
theStreamYouAreRecording.addTrack ( screenTrack );
So you must either record camera or screen. Do not replace tracks.

windows phone 8 official supported file icons

Does anyone know how to display the supported file type icons in WP8 ?
I have links on a xaml page which by clicking opens pdf, excel, word, powerpoints etc and these work nicely.
I would like to get the "official" icon which I can see for example in the office app in WP8 next to the link to indicate what kind of a file is in question.
I know from the file mimeType (for example application/pdf) what file is in question
Does anyone know how to accomplish this ?
Thanks,
Jani
Firstly, you need to get app product id, then use below code to get stream for official icon.
But you couldn't get icon of apps which are not scanned by InstallationManager.FindPackages().
IEnumerable<Windows.ApplicationModel.Package> apps = Windows.Phone.Management.Deployment.InstallationManager.FindPackages();
foreach(var app in apps)
{
if(app.Id.ProductId.Equals("APP_ID", StringComparison.InvariantCultureIgnoreCase)
{
var token = p.GetThumbnailToken();
var name = app.Id.Name + SharedStorageAccessManager.GetSharedFileName(token);
await SharedStorageAccessManager.CopySharedFileAsync(ApplicationData.Current.LocalFolder, name, NameCollisionOption.ReplaceExisting, token);
var file = await ApplicationData.Current.LocalFolder.GetFileAsync(name);
var randomStream = await file.OpenReadAsync();
Stream stream = randomStream.AsStream();
}
}

Resources