From 25c5f95ad961d810f2ae5fd9eae50e3f0bd6d20f Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Sun, 20 Dec 2015 00:08:12 +0000 Subject: [PATCH] added white play button icon for notification controls; pause button soon to follow. Some checks for audioStreams being null added, along with minor semnatic restructuring of parseDashManifest() --- .../org/schabi/newpipe/ActionBarHandler.java | 5 +++ .../org/schabi/newpipe/BackgroundPlayer.java | 32 +++++++----------- .../youtube/YoutubeVideoExtractor.java | 28 +++++++++------ .../ic_play_arrow_white_48dp.png | Bin 0 -> 283 bytes .../ic_play_arrow_white_48dp.png | Bin 0 -> 220 bytes .../ic_play_arrow_white_48dp.png | Bin 0 -> 343 bytes .../ic_play_arrow_white_48dp.png | Bin 0 -> 461 bytes .../ic_play_arrow_white_48dp.png | Bin 0 -> 605 bytes 8 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_play_arrow_white_48dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_play_arrow_white_48dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_play_arrow_white_48dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_play_arrow_white_48dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_play_arrow_white_48dp.png 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 0000000000000000000000000000000000000000..547ef30aacdebbd5bc27a3831971aa49be8813f7 GIT binary patch literal 283 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhaw9(lSrhEy=Vy|FR(PyjfM61bK%=q7O8Xj0w7EPdhfr5^#S_IEwe==vgFzHZ{arrqiL9p^2}oCQR8HlO`a zfBt>_q&-EaGMH-9&z)oSy0%IOibq!5=i7xQ8?znl*Ho#q?l1C zmLwh%pdb>pKr}hv!ldkF|5nzo_`k zc}eR_hl%VF4-<)DT=alRfHl0KMErSu6_?hE1x;YW&OCE+==ML_XMw(D@O1TaS?83{ F1OO`naDo5; literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..a3c80e73daa9dc4b85cddf9421b7127a4e18ac5d GIT binary patch literal 220 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}b0D#hxyXAr*{ouNm?la*%QRSeCek zK}3Xig#+sj2GIvh!e1Mh%dY8tm)JkC<%w#{kNWLqKY43+mi=hInq~SfM{=M2eECLk zbvI##h#NZ@*2LVfaQK$+p6S94LraHmPZSsgTe~DWM4fm)lPg literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..be5c062b5feeba5eff766b2fdae6dccb60cb4b0e GIT binary patch literal 343 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%&M7z$oYG;uuoF`1aODUuH)UwnS^i z62=e)(*V{`2k`*b5=Y_d%(4?EPx_&_WMu+pnDW{BolE^Uxj)}+yLIc`8R zg{90Lt0f&`?lL^eViO2AZ`iSm@yJ!6R31a2DNst&xD8@?udTeN#I8%r_sg2!eom$?*X_%R&Z!t~|1-cBYK4gm#+1_nk5gW={^?qALV VOCpPJ@c;vi!PC{xWt~$(69D@(h;je` literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..2745c3ab9297e89453fc82f5d3fd2aba163e3b37 GIT binary patch literal 461 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q1xWh(YZ)^zFi!DwaSW+oe0%4hCv%{L+r=G) znT%lzOe0!DGsL4>%MyiO9^|{TyY%sUrH;mw9Rd=LHutq1ECuvCCvX3G-WUyRuAF)L z=AXNp|MkzPod4UBc}q#z?Q^CJ9zU;^|7`KRf$#jkxaVvagf8UG|7;`P@a_D=d(Xr! zoVVQ9VZWfqenB501XPBM2&zX@Ao_^^g!h}1-e=@r3LF1d_$-XXz6+p4;3$0!>08tq4uJx_E zBNzhMWhb2Wg^F?Q^1c@%%<zopr02sN!rT_o{ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..8dbc4ea7c14058ce91746c5bc1767f49389f769e GIT binary patch literal 605 zcmeAS@N?(olHy`uVBq!ia0vp^2SAvE1xWt5x}=AJfl0;F#WAFU@y$U)Mg|5B<^@kT z{Lei)^PoHjPze$^5Wf9#jCFYqPauO^;0%`)d|3glS}&TkG%~6$G}Z*4jB7NM?mjo; z@4x6n=7&E%tDL@j_0`*b)%Q#rvh2%m*fyl?|GxG5T?P$?bKf_zGpHUYyY)MdQH0_7 z?>ov3EDvf5=PxJW*4R(HvUkbSv^anH4(o|{!&@Kx<#v_GX3Vp#0 zKxcFSoguTF;gJQa0E$%Z943Yj@$a^n+c)WbnZALicH+XjvSrWtH@@nt{-kl}utoo3 zMwNq{3cP*{i3Lm^&B6{6a~Sr_dhs-d!Lfje1IU-0!|><