title: youtubeExtractor for Android
body: <p>I want to use youtubeExtractor for android app and I found library like</p>
  
  <pre><code>compile 'com.github.HaarigerHarald:android-youtubeExtractor:master-SNAPSHOT'
  </code></pre>
  
  <p>There is a sample code in github I copied it. After I open app, it closes at the same time. There isn't an error in phone and also Logcat. Only there is 
  W/System: ClassLoader referenced unknown path: /data/app/oz.videos-1/lib/arm64 on logcat. I am not sure this is a error or not. Any suggestion? Thanks in advance.</p>
  
  <pre><code>import android.app.Activity;
  import android.app.DownloadManager;
  import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.os.Environment;
  import android.util.SparseArray;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.LinearLayout;
  import android.widget.ProgressBar;
  import android.widget.Toast;
  
  import at.huber.youtubeExtractor.VideoMeta;
  import at.huber.youtubeExtractor.YouTubeExtractor;
  import at.huber.youtubeExtractor.YtFile;
  
  public class MainActivity extends Activity
  {
  
  private static String youtubeLink;
  
  private LinearLayout mainLayout;
  private ProgressBar mainProgressBar;
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      mainLayout = (LinearLayout) findViewById(R.id.main_layout);
      mainProgressBar = (ProgressBar) findViewById(R.id.prgrBar);
  
      // Check how it was started and if we can get the youtube link
      if (savedInstanceState == null &amp;&amp; Intent.ACTION_SEND.equals(getIntent().getAction())
              &amp;&amp; getIntent().getType() != null &amp;&amp; "text/plain".equals(getIntent().getType()))
      {
  
          String ytLink = getIntent().getStringExtra(Intent.EXTRA_TEXT);
  
          if (ytLink != null
                  &amp;&amp; (ytLink.contains("://youtu.be/") || ytLink.contains("youtube.com/watch?v=")))
          {
              youtubeLink = ytLink;
              // We have a valid link
              getYoutubeDownloadUrl(youtubeLink);
          }
          else
          {
              Toast.makeText(this, R.string.error_no_yt_link, Toast.LENGTH_LONG).show();
              finish();
          }
      } else if (savedInstanceState != null &amp;&amp; youtubeLink != null) {
          getYoutubeDownloadUrl(youtubeLink);
      } else {
          finish();
      }
  }
  
  private void getYoutubeDownloadUrl(String youtubeLink)
  {
      new YouTubeExtractor(this)
      {
  
          @Override
          public void onExtractionComplete(SparseArray&lt;YtFile&gt; ytFiles, VideoMeta vMeta) {
              mainProgressBar.setVisibility(View.GONE);
  
              if (ytFiles == null) {
                  // Something went wrong we got no urls. Always check this.
                  finish();
                  return;
              }
              // Iterate over itags
              for (int i = 0, itag; i &lt; ytFiles.size(); i++) {
                  itag = ytFiles.keyAt(i);
                  // ytFile represents one file with its url and meta data
                  YtFile ytFile = ytFiles.get(itag);
  
                  // Just add videos in a decent format =&gt; height -1 = audio
                  if (ytFile.getFormat().getHeight() == -1 || ytFile.getFormat().getHeight() &gt;= 360) {
                      addButtonToMainLayout(vMeta.getTitle(), ytFile);
                  }
              }
          }
      }.extract(youtubeLink, true, false);
  }
  
  private void addButtonToMainLayout(final String videoTitle, final YtFile ytfile)
  {
      // Display some buttons and let the user choose the format
      String btnText = (ytfile.getFormat().getHeight() == -1) ? "Audio " +
              ytfile.getFormat().getAudioBitrate() + " kbit/s" :
              ytfile.getFormat().getHeight() + "p";
      btnText += (ytfile.getFormat().isDashContainer()) ? " dash" : "";
      Button btn = new Button(this);
      btn.setText(btnText);
      btn.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              String filename;
              if (videoTitle.length() &gt; 55) {
                  filename = videoTitle.substring(0, 55) + "." + ytfile.getFormat().getExt();
              } else {
                  filename = videoTitle + "." + ytfile.getFormat().getExt();
              }
              filename = filename.replaceAll("\\\\|&gt;|&lt;|\"|\\||\\*|\\?|%|:|#|/", "");
              downloadFromUrl(ytfile.getUrl(), videoTitle, filename);
              finish();
          }
      });
      mainLayout.addView(btn);
  }
  
  private void downloadFromUrl(String youtubeDlUrl, String downloadTitle, String fileName)
  {
      Uri uri = Uri.parse(youtubeDlUrl);
      DownloadManager.Request request = new DownloadManager.Request(uri);
      request.setTitle(downloadTitle);
  
      request.allowScanningByMediaScanner();
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
      request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
  
      DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
      manager.enqueue(request);
  }
  }
  </code></pre>