* fixed counterintuitive back button behaviour in PlayVideoActivity; see https://github.com/theScrabi/NewPipe/issues/99

* fixed a rarely-caused NullPointerException caused by a related video's view-count field being missing
This commit is contained in:
Adam Howard 2015-11-19 00:08:51 +00:00
parent 91f98c125e
commit 23e0196fcc
2 changed files with 40 additions and 7 deletions

View File

@ -15,6 +15,7 @@ import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.Display; import android.view.Display;
import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -86,7 +87,30 @@ public class PlayVideoActivity extends AppCompatActivity {
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent(); Intent intent = getIntent();
if(mediaController == null) { if(mediaController == null) {
mediaController = new MediaController(this); //prevents back button hiding media controller controls (after showing them)
//instead of exiting video
//see http://stackoverflow.com/questions/6051825
//also solves https://github.com/theScrabi/NewPipe/issues/99
mediaController = new MediaController(this) {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
final boolean uniqueDown = event.getRepeatCount() == 0
&& event.getAction() == KeyEvent.ACTION_DOWN;
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (uniqueDown)
{
if (isShowing()) {
finish();
} else {
hide();
}
}
return true;
}
return super.dispatchKeyEvent(event);
}
};
} }
position = intent.getIntExtra(START_POSITION, 0)*1000;//convert from seconds to milliseconds position = intent.getIntExtra(START_POSITION, 0)*1000;//convert from seconds to milliseconds

View File

@ -494,7 +494,7 @@ public class YoutubeExtractor extends Extractor {
* which is a subset of the fields in a full VideoInfo.*/ * which is a subset of the fields in a full VideoInfo.*/
private VideoPreviewInfo extractVideoPreviewInfo(Element li) { private VideoPreviewInfo extractVideoPreviewInfo(Element li) {
VideoPreviewInfo info = new VideoPreviewInfo(); VideoPreviewInfo info = new VideoPreviewInfo();
info.webpage_url = li.select("a[class*=\"content-link\"]").first() info.webpage_url = li.select("a.content-link").first()
.attr("abs:href"); .attr("abs:href");
try { try {
info.id = matchGroup1("v=([0-9a-zA-Z-]*)", info.webpage_url); info.id = matchGroup1("v=([0-9a-zA-Z-]*)", info.webpage_url);
@ -503,12 +503,21 @@ public class YoutubeExtractor extends Extractor {
} }
//todo: check NullPointerException causing //todo: check NullPointerException causing
info.title = li.select("span[class=\"title\"]").first().text(); info.title = li.select("span.title").first().text();
info.view_count = Long.parseLong(li.select("span[class*=\"view-count\"]") //this page causes the NullPointerException, after finding it by searching for "tjvg":
//https://www.youtube.com/watch?v=Uqg0aEhLFAg
String views = li.select("span.view-count").first().text();
Log.i(TAG, "title:"+info.title);
Log.i(TAG, "view count:"+views);
try {
info.view_count = Long.parseLong(li.select("span.view-count")
.first().text().replaceAll("[^\\d]", "")); .first().text().replaceAll("[^\\d]", ""));
info.uploader = li.select("span[class=\"g-hovercard\"]").first().text(); } catch (NullPointerException e) {//related videos sometimes have no view count
info.view_count = 0;
}
info.uploader = li.select("span.g-hovercard").first().text();
info.duration = li.select("span[class=\"video-time\"]").first().text(); info.duration = li.select("span.video-time").first().text();
Element img = li.select("img").first(); Element img = li.select("img").first();
info.thumbnail_url = img.attr("abs:src"); info.thumbnail_url = img.attr("abs:src");