diff --git a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java index 7372f7db8..28fbbac37 100644 --- a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java +++ b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java @@ -120,6 +120,9 @@ class ActionBarHandler { } } } + else { + Log.e(TAG, "FAILED to set audioStream value!"); + } } private void selectFormatItem(int i) { @@ -301,6 +304,8 @@ class ActionBarHandler { intent = new Intent(activity, BackgroundPlayer.class); intent.setAction(Intent.ACTION_VIEW); + Log.i(TAG, "audioStream is null:" + (audioStream == null)); + Log.i(TAG, "audioStream.url is null:"+(audioStream.url==null)); intent.setDataAndType(Uri.parse(audioStream.url), MediaFormat.getMimeById(audioStream.format)); intent.putExtra(Intent.EXTRA_TITLE, videoTitle); diff --git a/app/src/main/java/org/schabi/newpipe/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/BackgroundPlayer.java index 7c73d4402..443f7f846 100644 --- a/app/src/main/java/org/schabi/newpipe/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/BackgroundPlayer.java @@ -45,8 +45,6 @@ public class BackgroundPlayer extends Service /*implements MediaPlayer.OnPrepare private static final String TAG = BackgroundPlayer.class.toString(); private static final String ACTION_STOP = TAG+".STOP"; private static final String ACTION_PLAYPAUSE = TAG+".PLAYPAUSE"; - //private Looper mServiceLooper; - //private ServiceHandler mServiceHandler; public BackgroundPlayer() { super(); @@ -138,29 +136,23 @@ public class BackgroundPlayer extends Service /*implements MediaPlayer.OnPrepare wifiLock.acquire(); mediaPlayer.start(); - //mediaPlayer.getCurrentPosition() - int vidLength = mediaPlayer.getDuration(); - - //Intent genericIntent = new Intent(owner, owner.getClass()); - - //PendingIntent playPI = PendingIntent.getService(owner, noteID, genericIntent, 0); - PendingIntent playPI = PendingIntent.getBroadcast(owner, noteID, new Intent(ACTION_PLAYPAUSE), PendingIntent.FLAG_UPDATE_CURRENT); - - NotificationCompat.Action.Builder buttonBuilder = - new NotificationCompat.Action.Builder(R.drawable.ic_play_arrow_black, - "Play", playPI);//todo:translatable string - NotificationCompat.Action playButton = buttonBuilder.build(); - - PendingIntent stopPI = PendingIntent.getBroadcast(owner, noteID, - new Intent(ACTION_STOP), PendingIntent.FLAG_UPDATE_CURRENT); - IntentFilter filter = new IntentFilter(); filter.setPriority(Integer.MAX_VALUE); filter.addAction(ACTION_PLAYPAUSE); filter.addAction(ACTION_STOP); registerReceiver(broadcastReceiver, filter); - //playPauseButton + PendingIntent playPI = PendingIntent.getBroadcast(owner, noteID, new Intent(ACTION_PLAYPAUSE), PendingIntent.FLAG_UPDATE_CURRENT); + + NotificationCompat.Action playButton = new NotificationCompat.Action.Builder + (R.drawable.ic_play_arrow_white_48dp, "Play", playPI).build(); + + NotificationCompat.Action pauseButton = new NotificationCompat.Action.Builder + (R.drawable.ic_play_arrow_white_48dp, "Pause", playPI).build(); + + PendingIntent stopPI = PendingIntent.getBroadcast(owner, noteID, + new Intent(ACTION_STOP), PendingIntent.FLAG_UPDATE_CURRENT); + //todo: make it so that tapping the notification brings you back to the Video's DetailActivity //using setContentIntent noteBuilder = new NotificationCompat.Builder(owner); @@ -232,7 +224,7 @@ public class BackgroundPlayer extends Service /*implements MediaPlayer.OnPrepare //noteBuilder.setProgress(0, 0, false);//remove progress bar noteMgr.cancel(noteID);//remove notification unregisterReceiver(broadcastReceiver); - mediaPlayer.release();//release system resources + mediaPlayer.release();//release mediaPlayer's system resources wifiLock.release();//release wifilock diff --git a/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java b/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java index 3112d7f0c..82eba52e9 100644 --- a/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java @@ -371,6 +371,16 @@ public class YoutubeVideoExtractor extends VideoExtractor { //todo: replace this with a call to getVideoId, if possible videoInfo.id = matchGroup1("v=([0-9a-zA-Z_-]{11})", pageUrl); + if(videoInfo.audioStreams == null + || videoInfo.audioStreams.length == 0) { + Log.e(TAG, "uninitialised audio streams!"); + } + + if(videoInfo.videoStreams == null + || videoInfo.videoStreams.length == 0) { + Log.e(TAG, "uninitialised video streams!"); + } + videoInfo.age_limit = 0; //average rating @@ -445,13 +455,14 @@ public class YoutubeVideoExtractor extends VideoExtractor { try { XmlPullParser parser = Xml.newPullParser(); parser.setInput(new StringReader(dashDoc)); - int eventType = parser.getEventType(); String tagName = ""; String currentMimeType = ""; int currentBandwidth = -1; int currentSamplingRate = -1; boolean currentTagIsBaseUrl = false; - while(eventType != XmlPullParser.END_DOCUMENT) { + for(int eventType = parser.getEventType(); + eventType != XmlPullParser.END_DOCUMENT; + eventType = parser.next() ) { switch(eventType) { case XmlPullParser.START_TAG: tagName = parser.getName(); @@ -465,8 +476,8 @@ public class YoutubeVideoExtractor extends VideoExtractor { } else if(tagName.equals("BaseURL")) { currentTagIsBaseUrl = true; } - break; + case XmlPullParser.TEXT: if(currentTagIsBaseUrl && (currentMimeType.contains("audio"))) { @@ -479,16 +490,14 @@ public class YoutubeVideoExtractor extends VideoExtractor { audioStreams.add(new VideoInfo.AudioStream(parser.getText(), format, currentBandwidth, currentSamplingRate)); } + //missing break here? case XmlPullParser.END_TAG: if(tagName.equals("AdaptationSet")) { currentMimeType = ""; } else if(tagName.equals("BaseURL")) { currentTagIsBaseUrl = false; - } - break; - default: + }//no break needed here } - eventType = parser.next(); } } catch(Exception e) { e.printStackTrace(); @@ -583,10 +592,7 @@ public class YoutubeVideoExtractor extends VideoExtractor { e.printStackTrace(); } Context.exit(); - if(result != null) - return result.toString(); - else - return ""; + return (result == null ? "" : result.toString()); } private String cleanUrl(String complexUrl) { diff --git a/app/src/main/res/drawable-hdpi/ic_play_arrow_white_48dp.png b/app/src/main/res/drawable-hdpi/ic_play_arrow_white_48dp.png new file mode 100644 index 000000000..547ef30aa Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_play_arrow_white_48dp.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_play_arrow_white_48dp.png b/app/src/main/res/drawable-mdpi/ic_play_arrow_white_48dp.png new file mode 100644 index 000000000..a3c80e73d Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_play_arrow_white_48dp.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_play_arrow_white_48dp.png b/app/src/main/res/drawable-xhdpi/ic_play_arrow_white_48dp.png new file mode 100644 index 000000000..be5c062b5 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_play_arrow_white_48dp.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_play_arrow_white_48dp.png b/app/src/main/res/drawable-xxhdpi/ic_play_arrow_white_48dp.png new file mode 100644 index 000000000..2745c3ab9 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_play_arrow_white_48dp.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_play_arrow_white_48dp.png b/app/src/main/res/drawable-xxxhdpi/ic_play_arrow_white_48dp.png new file mode 100644 index 000000000..8dbc4ea7c Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_play_arrow_white_48dp.png differ