title: Sorry, this video cannot be played - streaming mp4 to android
body: <p>I've searched all over for a solution to this (including SO), however still haven't found a solution.</p>
  
  <p>I need to have a simple video playback in my app.  It's a bit less straightforward than a simple window with a video.  Simplified, I have two layouts on my screen, one containing some other stuff and the other is to have the video window.  There's also a button to switch between the two.  This all works just fine, after I figured out that the videoview cannot  be present on a view with visibility 'gone' - therefore I'm adding/removing it to/from container layout when needed.</p>
  
  <p>However, I have the problem with the actual video playback.  When I try to activate it, I get the dreaded error <code>Sorry, this video cannot be played.</code>  One of the questions here on SO is discussing video formats (<a href="https://stackoverflow.com/questions/2544365/android-cant-play-any-videos-mp4-mov-3gp-etc">Android -- Can&#39;t play any videos (mp4/mov/3gp/etc.)?</a>) - however I already have what seems to be the correct format, with 320px width and everything else.  One of the answers on that thread mentions that videos from <a href="http://www.law.duke.edu/cspd/contest/finalists/" rel="nofollow noreferrer">here</a> "definitely work". I tried a couple from there - but I got another common beast: <code>Sorry, this video is not valid for streaming to this device.</code></p>
  
  <p>Please note that I'm testing on an actual device, as video playback is not working in the emulator.  Also note that the solution must work on Android 1.6 and above (client's requirement).  The device I'm testing on is LG GT540 Optimus with Android 2.1 (at present I don't have any other devices available).</p>
  
  <p>From what I figured out, if I don't use <code>qt-faststart</code> on the videos, I get error <code>Sorry, this video is not valid for streaming to this device.</code>  If I do use <code>qt-faststart</code>, then I get <code>Sorry, this video cannot be played.</code></p>
  
  <p>Here's my code for the playback:</p>
  
  <pre><code>VideoViewer videoPlayer = new VideoViewer(this);
  MediaController mediaController = new MediaController(this);
  mediaController.setAnchorView(videoPlayer);
  videoPlayer.setMediaController(mediaController);
  videoPlayer.setVideoURI(Uri.parse(object.getVideoURL()));
  LinearLayout container = (LinearLayout)ObjectInfo.this.findViewById(R.id.VideoContainer);
  container.setVisibility(VISIBLE);
  container.addView(videoPlayer, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  videoPlayer.requestFocus();
  videoPlayer.start();
  </code></pre>
  
  <p>Now, the video I'm trying to play is to be progressive-downloaded from HTTP: <code>object.getVideoURL()</code> returns <a href="http://www.ooklnet.com/files/381/381489/video.mp4" rel="nofollow noreferrer">http://www.ooklnet.com/files/381/381489/video.mp4</a></p>
  
  <p>Can anybody please help me sort this out?  This is the last thing I need to complete before the whole app is ready.</p>
  
  <p>Many thanks!</p>
  
  <p><strong>Edit:</strong> I tried using MediaPlayer - but got even worse results than with VideoView, so went back to VideoView.  Now, in simulator, I get a black screen with controls hovering over it and the sound of the video is playing fine, also the progress is adjusting as the playback continues.  However on my actual device, I'm still getting <code>Sorry, this video cannot be played.</code> error</p>