title: Play a video on android device
body: <p>i'm tring to display a youtube video on android. I googled but I can't find any solution to my last error:</p>
  
  <pre><code>08-16 12:05:55.950: E/MediaPlayer(2418): error (1, -2147483648)
  08-16 12:05:56.274: E/MediaPlayer(2418): Error (1,-2147483648)
  </code></pre>
  
  <p>I added to Manifest file user permission to internet:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.myapp"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="17" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
  
          &lt;activity
              android:name="com.example.myapp.MainActivity"&gt;
  
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name="com.example.myapp.MovieActivity"
              android:parentActivityName="com.example.myapp.MainActivity"&gt;
  
              &lt;meta-data
              android:name="android.support.PARENT_ACTIVITY"
              android:value="com.example.myapp.MainActivity" /&gt;
  
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>this is my MovieActivity.java:</p>
  
  <pre><code>package com.example.myapp;
  
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.HashMap;
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import org.w3c.dom.Attr;
  import org.w3c.dom.Document;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.AsyncTask;
  import android.os.Build;
  import android.os.Bundle;
  import android.renderscript.Element;
  import android.support.v4.app.NavUtils;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.ImageView;
  import android.widget.MediaController;
  import android.widget.ProgressBar;
  import android.widget.TextView;
  import android.widget.VideoView;
  
  @SuppressLint("NewApi")
  public class MovieActivity extends Activity
  {
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.movie_activity);
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) 
      {
          getActionBar().setDisplayHomeAsUpEnabled(true);
      }
      ImageView m_avatar = (ImageView) findViewById(R.id.Avatar);
      m_avatar.setImageResource(R.drawable.lambda);
  
      TextView m_pagedescription = (TextView) findViewById( R.id.pageDescription);
      m_pagedescription.setText("What do you like to do?");
  
      TextView m_nickname = (TextView) findViewById(R.id.nickName);
      m_nickname.setText("User");
  
      new MoviePlayer("http://www.youtube.com/watch?v=1FJHYqE0RDg",this).execute();
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) 
  {
      switch (item.getItemId()) 
      {
          case android.R.id.home:
              NavUtils.navigateUpFromSameTask(this);
              return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu)
  {
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  public void btnSkip_OnClick(View v)
  {
      Intent intent = new Intent(this, MainActivity.class);
      startActivity(intent);
  }
  
  public class MoviePlayer extends  AsyncTask&lt;Void, Void, Void&gt;
  {
      ProgressBar m_progressBar;
      VideoView m_movieView;
      String m_movieUrl;
      MediaController m_mc;
      Context c;
      public MoviePlayer(final String url, Context context)
      {
          c = context;
          m_movieUrl = url;
          m_progressBar = (ProgressBar) findViewById(R.id.progressBar);
          m_movieView = (VideoView) findViewById(R.id.movie);
          m_mc = (MediaController) findViewById(R.id.mediaController);
      }
  
     @Override
      protected void onPreExecute()
      {
          super.onPreExecute();
          m_progressBar.setVisibility(View.VISIBLE);
          m_movieView.setVisibility(View.GONE);
      }
  
      @SuppressLint("NewApi")
      @Override
      protected Void doInBackground(Void... params)
      {
          try
          {
              if(m_movieUrl.isEmpty())
              {
                  String url = "http://www.youtube.com/watch?v=1FJHYqE0RDg";
                  m_movieUrl = getUrlVideoRTSP(url);
              }
              Log.e("Video url for playing=========&gt;&gt;&gt;&gt;&gt;", m_movieUrl);
          }
          catch (Exception e)
          {
              Log.e("Login Soap Calling in Exception", e.toString());
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result)
      {
          super.onPostExecute(result);
          m_progressBar.setVisibility(View.GONE);
          m_movieView.setVisibility(View.VISIBLE);
  
          m_movieView.setVideoURI(Uri.parse(m_movieUrl));
          m_mc = new MediaController(c);
          m_movieView.setMediaController(m_mc);
          m_movieView.requestFocus();
          m_movieView.start();          
          m_mc.show();
      }
  
      public String getUrlVideoRTSP(String urlYoutube)
      {
          try
          {
              String gdy = "http://gdata.youtube.com/feeds/api/videos/";
              DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
              String id = extractYoutubeId(urlYoutube);
              URL url = new URL(gdy + id);
              HttpURLConnection connection = (HttpURLConnection) url.openConnection();
              Document doc = documentBuilder.parse(connection.getInputStream());
              Element el = (Element) doc.getDocumentElement();
              NodeList list = ((Document) el).getElementsByTagName("media:content");///media:content
              String cursor = urlYoutube;
              for (int i = 0; i &lt; list.getLength(); i++)
              {
                  Node node = list.item(i);
                  if (node != null)
                  {
                      NamedNodeMap nodeMap = node.getAttributes();
                      HashMap&lt;String, String&gt; maps = new HashMap&lt;String, String&gt;();
                      for (int j = 0; j &lt; nodeMap.getLength(); j++)
                      {
                          Attr att = (Attr) nodeMap.item(j);
                          maps.put(att.getName(), att.getValue());
                      }
                      if (maps.containsKey("yt:format"))
                      {
                          String f = maps.get("yt:format");
                          if (maps.containsKey("url"))
                          {
                              cursor = maps.get("url");
                          }
                          if (f.equals("1"))
                              return cursor;
                      }
                  }
              }
              return cursor;
          }
          catch (Exception ex)
          {
              Log.e("Get Url Video RTSP Exception======&gt;&gt;", ex.toString());
          }
          return urlYoutube;
  
      }
  
      protected String extractYoutubeId(String url) throws MalformedURLException
      {
          String id = null;
          try
          {
              String query = new URL(url).getQuery();
              if (query != null)
              {
                  String[] param = query.split("&amp;");
                  for (String row : param)
                  {
                      String[] param1 = row.split("=");
                      if (param1[0].equals("v"))
                      {
                          id = param1[1];
                      }
                  }
              }
              else
              {
                  if (url.contains("embed"))
                  {
                      id = url.substring(url.lastIndexOf("/") + 1);
                  }
              }
          }
          catch (Exception ex)
          {
              Log.e("Exception", ex.toString());
              }
              return id;
          }       
  }
  }
  </code></pre>
  
  <p>and finally this is my movie_activity.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt;
  
  &lt;ImageView
      android:id="@+id/Avatar"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:adjustViewBounds="true"
      android:contentDescription="@string/Avatar"
      android:maxHeight="80dp"
      android:maxWidth="80dp"
      android:src="@drawable/ic_launcher"&gt;
  &lt;/ImageView&gt;
  
  &lt;TextView
      android:id="@+id/nickName"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_alignBottom="@id/Avatar"
      android:layout_alignParentTop="true"
      android:layout_toRightOf="@id/Avatar"
      android:gravity="center_vertical"
      android:maxLength="15"
      android:paddingLeft="16dp"
      android:text="@string/nicknamePH"
      android:textAlignment="gravity"
      android:textAppearance="?android:attr/textAppearanceLarge" &gt;
  &lt;/TextView&gt;
  
  &lt;View
      android:id="@+id/Ruler1"
      android:layout_width="fill_parent"
      android:layout_height="1dp"
      android:layout_below="@id/nickName"
      android:background="#000000"&gt;
  &lt;/View&gt;
  
  &lt;TextView
      android:id="@+id/pageDescription"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_below="@id/Ruler1"
      android:gravity="center_vertical|center_horizontal"
      android:text="@string/pageDescription"
      android:textAlignment="gravity"
      android:textAppearance="?android:attr/textAppearanceSmall"&gt;
  &lt;/TextView&gt;
  
  &lt;View
      android:id="@+id/Ruler2"
      android:layout_width="fill_parent"
      android:layout_height="1dp"        
      android:background="#000000"
      android:layout_below="@id/pageDescription"&gt;
  &lt;/View&gt;
  
  &lt;Button
      android:id="@+id/Skip"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:onClick="btnSkip_OnClick"
      android:text="@string/skipebutton"&gt;
  &lt;/Button&gt;
  
  &lt;TextView
          android:id="@+id/details"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_above="@id/Skip"
          android:clickable="true"
          android:gravity="center_vertical|center_horizontal"
          android:linksClickable="true"
          android:text="@string/detailspc"
          android:textAlignment="gravity"
          android:textAppearance="?android:attr/textAppearanceLarge" &gt;
  &lt;/TextView&gt;
  
  &lt;MediaController
      android:id="@+id/mediaController"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_above="@id/details" &gt;
  &lt;/MediaController&gt;
  
  &lt;FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/Ruler2" android:layout_above="@id/mediaController"&gt;
  
      &lt;VideoView
          android:id="@+id/movie"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"&gt;
      &lt;/VideoView&gt;
      &lt;!--
      &lt;ProgressDialog
          android:id="@+id/progressDialog"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center_vertical"&gt;
      &lt;/ProgressDialog&gt;
      --&gt;
  
      &lt;ProgressBar
          android:id="@+id/progressBar"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center_vertical|center_horizontal"
          android:contentDescription="@string/progressbar"
          android:indeterminate="true" &gt;
  
          &lt;/ProgressBar&gt;
  
  
      &lt;/FrameLayout&gt;      
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>On emulator when i try to run video i get just: "Can't play this video." error message.
  I read some post that blame the video format/resolution. If you think this is my case could be so kind to provide link that's supposed to work? 
  Error is not very explanatory of what was wrong. So maybe someone more skilled than me could help :)</p>
  
  <p>Thanks in advance for any hint.</p>