((I'm using the browser to enter the site, because app here is in trouble)
I'm pulling multiple results from a video formats on YouTube. However, when I step into the spinner, it only passes one result, which is usually the first, which is usually the audio. Then the (remaining) video formats of all spinner results do not appear.
Edited: First I see if the app received any valid YouTube link:
// Check how it was started and if we can get the youtube link
if (savedInstanceState == null && Intent.ACTION_SEND.equals(getIntent().getAction())
&& getIntent().getType() != null && "text/plain".equals(getIntent().getType())) {
String ytLink = getIntent().getStringExtra(Intent.EXTRA_TEXT);
if (ytLink != null
&& (ytLink.contains("://youtu.be/") || ytLink.contains("youtube.com/watch?v="))) {
youtubeLink = ytLink;
// We have a valid link
getUrl(youtubeLink);
} else {
Toast.makeText(this, R.string.app_name, Toast.LENGTH_LONG).show();
finish();
}
} else if (savedInstanceState != null && youtubeLink != null) {
getUrl(youtubeLink);
} else {
//finish();
}
}
Then I take the link to convert and expand the app action (formats) and then I send the result to a new method so that the spinner download options are added:
private void getUrl(String youtubeLink) {
new YouTubeExtractor(this) {
@Override
public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta) {
if (ytFiles == null) {
// Something went wrong we got no urls. Always check this.
finish();
return;
}
// Iterate over itags
for (int i = 0, itag; i < 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 => height -1 = audio
if (ytFile.getFormat().getHeight() == -1 || ytFile.getFormat().getHeight() >= 360) {
}
initSpinner(vMeta.getTitle(), ytFile);
}
}
}.extract(youtubeLink, true, false);
}
New method for adding * format options in spinner:
public void initSpinner(final String videoTitle, final YtFile ytfile){
spinner = (Spinner) findViewById(R.id.spinner);
// Display some buttons and let the user choose the format
String opcFrmt = (ytfile.getFormat().getHeight() == -1) ? "Audio " +
ytfile.getFormat().getAudioBitrate() + " kbit/s":
ytfile.getFormat().getHeight() + "p";
opcFrmt += (ytfile.getFormat().isDashContainer()) ? " dash" : "";
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> strList = new ArrayList<String>();
//return the list representation of array
strList.add(opcFrmt);
strList.add(opcFrmt);
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, strList);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
}
The problem is that all of this only appears in the spinner.