Skip to main content

Quick and dirty Android YouTube fullscreen sample code.

I am currently developing an application that requires playing YouTube videos in full screen mode. After scraping around and putting together the pieces, I currently have the following code which I hope is of use to anybody else out there.


  public void playYouTubeVideo(String videoId) {

    String videoTemplate = "@YTBASE@@VIDEO@";

    String videoAction = videoTemplate
        .replace("@YTBASE@", "vnd.youtube://")
        .replace("@VIDEO@", videoId);

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(videoAction));
    intent.putExtra("VIDEO_ID", videoAction);
    intent.putExtra("force_fullscreen", true);

    startActivity(intent);
  }

There are some points to bear in mind though...
  1. Once the ACTION_VIEW intent has control, your application is effectively paused i.e. it won't work until you use the back button to exit the player intent and return to your application.
  2. It may or may not work in the future of YT change the way they operate, but that's always the case.
Point 2 is the reason I have used the variables videoTemplate and the @ delimited markers... hopefully you can see what's going on there and change it in the future if you need to.

I now realise that I may well have to use the "official" YouTube API and create an application API key and all the rest of it but if it means seamless integration then I will do just that but I thought I'd at least share what I had so far.

So, I hope the above serves useful to you. Back to the hack...


Comments

Popular posts from this blog

The Coolest Shortest PHP Function I Will Ever Write

Having now released my own programming language, FELT , and learned a lot about this and that in the process I have of late, in the evenings, been struggling to reconcile my love of LISP and how simple FELT makes some PHP coding task leaner and meaner with the fact that I still have to use PHP for my day job. In my language, FELT , I have used the square brackets to define a "normal" array and curly braces to define a "key-value" array, mainly because this is identical to JSON format and anybody familiar with Javascript coding just won't have any issues getting to grips with that now will they! Let's take some simple examples of FELT code: (defvar simple-array [1 2 3 4]) (defvar simple-map {:name "Eric" :age 42 :occupation "Viking Hacker"}) When FELT has done its thing, we get the following PHP code, $simple_array = array(1, 2, 3, 4); $simple_map = array('name' => "Eric", 'age' => 42, ...

Prime Peace

I think prime numbers are the numerical expression of peace. Restful nodes in the vibration of everything. Prime factorisation has always struck me as something truly astounding and it is reassuring to know that awsesome minds are hard at work trying to solve the Riemann hypothesis right now. There are some truly wonderful professional and amateur (in the nicest sense of the word) explorations I have watched recently and the ones that moved me the most, in order of cool factor were: This guy,Carlos Paris, has put in some serious work with AutoCAD and made some interesting observations. I truly enjoyed watching all of his four videos. Awesome work Carlos. As an interested amateur I found his work and thoughts to be very compelling. I am sure the professionals would groan or moan but to me this video is most excellent and informative. Speaking of the professionals, this video is also very interesting to watch as it goes some way to visually explaining the Riemann hypothesis in...

Emacs fat fringes and colours

Having gotten used to various editors implementations of distraction free or presentation mode views, I figured that emacs could probably do something similar with little effort. As usual, it could. For me, distraction free means no clutter, no menu bars, tool bars, gutters, line numbers, just the code. The first step is to be able to set the size of the left and right margins to something large, 100px works quite well. I use Aquamacs a lot. This does not work in the terminal! So, here is the little bit of code you need to place into your beloved ~/.emacs file: (defun fringe-bars (width) (interactive "pWidth:") (fringe-mode (cons width width)) (set-face-attribute 'fringe nil :foreground (face-foreground 'default) :background (face-background 'default))) Then, using the Ctrl-U prefix, you would set the left and right margins to be whatever you want, let’s say we wanted to have 500px left and right, which wor...