YouTube for Glass

I released the first version of this app a couple of weeks ago, but I have finally finished polishing and optimizing it! This app allows you to watch YouTube videos on your Glass. The videos are taken from a YouTube feed and placed directly on your timeline, and you need only click on the video card that you want to watch and press “View Video” to get some video action rolling!


Watch YouTube on Glass!

You can get the source code for the app here: GitHub
You can download a compiled APK (and extras) here.

Installing this app from the compiled APK will use ADB. Please see my ADB tutorial if you do not have this working with your Glass. Getting it running is pretty simple actually. Just a few quick steps:

 

Installing the app

  1. Extract all the files in the same directory as ADB.
  2. Right click on the file .youtubeconfig and click “Edit” (or ‘Open with Notepad’)
  3. This is the configuration file, you will need to set it up to make the app work as you wish before you load it on your glass
    1. youtubeFeed should be set to the feed URL you wish to be sent to your Glass. I highly recommend you do your subscription feed if you are a YouTube user, and becoming a user and subscribing to some channels if you are not :) . If you go this route, you will want to un-comment the line
      `#youtubeFeed=http://gdata.youtube.com/feeds/base/users/<username>/newsubscriptionvideos`
      by removing the pound (#) sign. Then, replace `<username>` with your YouTube username. Next, comment out any other line that starts with “youtubeFeed=” by adding a pound sign to the beginning of it. Finally, copy the URL to your favorite browser to make sure it works!
    2. queryInterval is how often the app will download the feed and add new videos to your timeline, in minutes.
    3. sendAllVideos determines whether or not all videos in the feed are packaged together on your timeline every time a new video is posted. If you set this to `false`, only new videos will be put on your timeline as they come in. I recommend leaving it to true.
  4. Save the changes to your configuration file and open up a command window and browse to your adb directory.
  5. Type `adb push .youtubefeedconfig sdcard/`
  6. Type `adb install YoutubeFeeds.apk`
  7. Type `adb install com.google.android.youtube-2.apk`
  8. Type `adb shell am start -n com.appliedanalog.glass.youtube/.MainActivity`
  9. Put your Glasses on and check out your timeline.

Using the App

Once you have installed the app, you should see a new card on your timeline that tells you what YouTube feed is being pulled and how often it is being pulled. This is the controller card, you can use it to stop the feed whenever you want. When you stop the feed, the controller card is pinned to the front of your timeline. You can then use this to start your feed back up. I recommend that you do not delete this card as it will be very difficult to start the feed up if you do.


This is the controller card where you can start or stop the feed and view the configuration settings.

After a few moments (if you are connected to the Internet), you should see your first video feed show up in your timeline. From here you can tap into the feed and tap on a video to view it. The first time you view a video, Glass will ask you how you want to launch it. Use the touchpad to scroll to the bottom of the selection menu and select “Always use this option”, then select YouTube. From now on you won’t be bothered by this.


Videos show up on your timeline complete with thumbnail images and durations!

At the end of every video feed there will be a new controller card that you can use to stop the feed. You can use these when your original controller card gets (inevitably) lost in your timeline.

Good luck and have fun!
Uninstalling the App

  1. Open up a command prompt and browse to the folder that has adb.
  2. Type `adb uninstall com.appliedanalog.glass.youtube`
  3. Type `adb uninstall com.google.android.youtube`
  4. Done!

How to install native apps on Glass

The apps you can write with the version of Glass that Google shipped to the original explorers only has one documented API for developers. This is the Mirror API, a REST model that provides little in the way of user interaction and is primarily focused on beaming information to your eye. The really fun stuff you can do with Glass is done through what is being called “Native” apps, which are basically Android applications that are side-loaded and run on Glass. These applications have full access to the hardware and can do anything an Android application can do – that is, everything.

What is more important for those who have never developed for Android is: “How do I install and use these applications”? This is the topic of this post. This should be a step by step guide that gets you up and side-loading native applications onto Glass using a Windows computer as quickly as possible. This guide assumes no prior knowledge of debugging on Android so anybody should be able to use it. So let’s get to it!

Enabling Debug Mode on Glass
The first thing you need to do is tell Glass that you want to be able to debug on it. This is supported via a setting directly accessible from the stock Glass UI.

  1. Scroll to and select the settings card.
  2. Scroll to and select the “Device Info” card.
  3. Scroll over one to “Turn on debug” and press on it.
  4. Wait a moment and debugging is turned on!


Installing Drivers for Glass

So unfortunately, the stock android drivers for Windows does not properly support Windows. You can modify the drivers that come packaged with the android SDK to get this to work by following the instructions here, or you can use these drivers that I prepared, downloadable here.

Once you have downloaded the drivers or done the modifications, you will need to plug your Glass into your PC via a MicroUSB plug. Now, follow the instructions found here, using the drivers you downloaded where they are referenced. Please note that if you are using Linux or Apple, you will not need to install any drivers, you can just use the instructions found at that link to get past this step.

When you are done, your Device Manager window should look like this:


Using ADB

Normally ADB comes packaged as part of the Android SDK. However, you can get a standalone version here. Once you have grabbed this, follow these instructions:

  1. Extract the standalone ADB you obtained into some directory that you can come back to at a future date. Copy the directory path to your clipboard.
  2. Open a command prompt. You can do this on Windows 7 by pressing the Start Key, typing ‘cmd’ and hitting Enter. In Windows XP, open the start menu, click on “Run” and type “cmd”.
  3. Type `cd “`, then right click on the command prompt and click “Paste” to copy the directory path from Step (1). Type `”` and press Enter. (Command should be `cd “<directory>”`)
  4. Type `adb devices`. Verify that adb runs and that your glass shows up as a device. It should show up as just a seemingly random jumble of numbers and letters under “List of devices attached”. If all you see is “List of devices attached”, you have not installed the drivers properly.
  5. You’re up and running! You will need to repeat steps (2) and (3) every time you want to use adb.

OK, so you have ADB installed and it can talk to you Glass! Now, what do you do? Well, you came here to load some native apps, so lets do that! My recommendation for your first app is Launchy, an app that allows you to launch other native Glass applications by accessing the Settings card. You can find more information about Launchy and it’s brilliant author here. You can download a binary copy of it here.


Installing Native Apps

I’m sure anyone who has gotten this far already knows this, but it is worth rehashing just in case. Android apps are stored in files with the extension .apk. These files contain all of the program data necessary to run apps on your Android smartphone and on Glass. They are also easily loadable to a device connected via a USB cable using ADB. One of the magic things about Glass is that it is just an Android smartphone at heart, so you can theoretically load any Android application onto it, provided you can come across an APK file for that application. This opens up some exciting possibilities. I strongly urge you to watch this video from Google IO 2013 if this excites you!

So you’ve found an APK you want to install on your Glass, lets push that thing onto your device!

  1. Ensure your Glass is connected to your computer via a USB cable.
  2. Extract or place the APK file in the same directory as adb.exe.
  3. Follow steps (2) and (3) from “Using ADB” above.
  4. Type `adb install <your apk file>`, replacing <your apk file> with the APK filename from step (2).
  5. Verify that the command prompt reports “Success”.
  6. Launch the App to activate it.

So, about step (6). A clever thing that Google did with Android apps is it requires the user to launch an Android (or Glass) app before that app can actually do anything useful. This is a fundamental part of the operating system that no developer can get around. Even if the app doesn’t even do anything in the foreground, it must be launched by the user before it can do whatever it does in the background. Developers familiar with Android can launch apps using adb, but I’m trying to make this guide as easy as possible. So, I recommend you install Launchy, from the links above, which will assist you in easily launching applications.

OK James, you say, I’ll install Launchy, but how am I supposed to launch IT? Simply, using adb. For Launchy, and Launchy alone, you can use this command to start the program: `adb shell am start -n com.mikedg.android.glass.launchy/.MainActivity`. This will launch and activate Launchy.

 

Uninstalling Native Apps

This is probably the most unfortunate part of this whole series in that it is not exactly easy to write up a tutorial on how to uninstall native apps. To uninstall a native app, you will need to use adb and you will need to know the apps “package name”. This is the internal system identifier for the app. Every app I post here (at least until Google provides a better interface for this) I will include the package name so that you can use the following steps to uninstall it if you do not like it. The package name for Launchy is “com.mikedg.android.glass.launchy”. Steps to uninstall an app from Glass:

  1. Ensure your Glass is connected to your computer via a USB cable.
  2. Follow steps (2) and (3) from “Using ADB” above.
  3. Type this command `adb uninstall <package name>`.
  4. Verify “Success”.

 

So, you know how to install/uninstall native apps! Keep following this blog as I post some of my own!

 

Caution!

I feel compelled to mention this – APK’s are true and bonified Android apps. Since you cannot see the permissions (easily) that you are granting them when you sideload them in to your device, they could, feasibly, be doing anything. Be sure you know and trust the author of any APK you choose to sideload into your device before you do it. One beauty of Android is that there really isn’t any such a thing as a virus as long as your device isn’t rooted. If you unintentionally install a malicious program, it is as easy as uninstalling it to get rid of it. However, it’s best not to install the malicious program to begin with.

When it comes to apps from a stranger, really the only way you can be 100% safe is by building their apps from source code yourself. Most native apps I’ve seen thus far are open source, so you can download the source and verify that nothing is fishy before building and running it on your Glass. Unfortunately, this is not something I am comfortable writing a tutorial in. If you want to err on the side of safety but are not a developer, I recommend you wait until Google finishes the GDK, which will (presumably) come as an update that will allow you to load native apps to your Glass from a Google interface.

Glass HUD

My first app for Glass is “Glass HUD” – an application that displays readouts from sensors onboard Glass and your phone. With a little trickery, I managed to get this data to display on a pinned card on Glasses native timeline. You will need to use Launchy or some other Native App Launcher to launch the application but once it is up and running interfacing with it should be purely native.

Here is a video of the app working:

In order to get more than just the compass and accelerometer sensors I packaged with the Glass version, you will need to load a companion app on your phone. This app, which I will release on the Android Market in the coming months as “Applied Companion” will service not just this app, but all of my Glass apps that interface with your smartphone.

You can view the source code and build the app for yourself now:
https://github.com/neonglass/GlassHUD

Here are some notes on the code:

The main functionality of the app is encapsulated in a service, specifically GlassHUDService. This service aggregates sensor data, packages it into HTML viewable on the timeline, and pushes updates to the timeline. For the Android developers reading this, really the only code that might be new to you will be found at the bottom of GlassHUDService.java. It’s here you will find the TimelineUpdater class that is responsible for writing to the timeline.

I think I will be re-using this service-based model a lot with Glass Development. Accessing native apps, even with Launchy (see +Mike DiGiovanni ) is kind of a pain since you completely remove yourself from the Glass ecosystem and cannot do anything but access your app. By keeping your UI in a card with a backing Service that updates it and communicates with it, you are able to still use Glass as it was intended while your app runs.

It turns out you can update timeline items continuously and the results will show up pretty quickly in the main UI. I am seeing about a 2Hz update rate – not good enough for an animated GIF, but good enough for a lot of other things :) .

One issue I ran into early on was if your app does not record and re-use the TimelineItems it creates early on, you will end up with a glass timeline cluttered with cards from your app, which is definitely not desirable. I got around this by recording the ID of the first card I push in a SharedPreferences structure then fetching that card every time the app is launched from then on. I also put the card in a “disabled state” when the app is not running so it is not confusing to the user. Another option would be to delete the card after you use it.

The main activity for this app provides the users with some switches via classic android buttons. Classic android UI’s are still relatively navigable with Glass so this works fine. This was necessary for this app since the service consumes considerable CPU time when it is running (constantly polling bluetooth/sensors) so I needed a way to disable it. I can see other apps registering themselves to startup when Glass is powered on and run completely in the background so third party launchers like Launchy are not even necessary.

Proudly powered by WordPress
Theme: Esquire by Matthew Buchanan.