From 1ab5872857824c5b77e4a46089187b7a7dc095b4 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 21 Sep 2015 13:32:11 +0200 Subject: [PATCH] made player pause when screen is locked. started creating audiosupport --- .../org/schabi/newpipe/ActionBarHandler.java | 16 ++++++++-------- .../org/schabi/newpipe/PlayVideoActivity.java | 11 +++++++++++ .../java/org/schabi/newpipe/VideoInfo.java | 18 ++++++++++++++---- .../newpipe/VideoItemDetailFragment.java | 10 +++++----- .../newpipe/youtube/YoutubeExtractor.java | 15 ++++++++------- 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java index 1be21537f..201757f67 100644 --- a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java +++ b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java @@ -49,7 +49,7 @@ public class ActionBarHandler { private Context context = null; private String webisteUrl = ""; private AppCompatActivity activity; - private VideoInfo.Stream[] streams = null; + private VideoInfo.VideoStream[] videoStreams = null; private int selectedStream = -1; private String videoTitle = ""; @@ -75,8 +75,8 @@ public class ActionBarHandler { activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); } - public void setStreams(VideoInfo.Stream[] streams) { - this.streams = streams; + public void setStreams(VideoInfo.VideoStream[] streams) { + this.videoStreams = streams; selectedStream = 0; String[] itemArray = new String[streams.length]; String defaultResolution = defaultPreferences @@ -178,8 +178,8 @@ public class ActionBarHandler { Intent intent = new Intent(); try { intent.setAction(Intent.ACTION_VIEW); - intent.setDataAndType(Uri.parse(streams[selectedStream].url), - "video/" + streams[selectedStream].format); + intent.setDataAndType(Uri.parse(videoStreams[selectedStream].url), + "video/" + videoStreams[selectedStream].format); context.startActivity(intent); // HERE !!! } catch (Exception e) { e.printStackTrace(); @@ -205,7 +205,7 @@ public class ActionBarHandler { } else { Intent intent = new Intent(context, PlayVideoActivity.class); intent.putExtra(PlayVideoActivity.VIDEO_TITLE, videoTitle); - intent.putExtra(PlayVideoActivity.STREAM_URL, streams[selectedStream].url); + intent.putExtra(PlayVideoActivity.STREAM_URL, videoStreams[selectedStream].url); intent.putExtra(PlayVideoActivity.VIDEO_URL, webisteUrl); context.startActivity(intent); } @@ -217,7 +217,7 @@ public class ActionBarHandler { Log.d(TAG, "bla"); if(!videoTitle.isEmpty()) { String suffix = ""; - switch (streams[selectedStream].format) { + switch (videoStreams[selectedStream].format) { case VideoInfo.F_WEBM: suffix = ".webm"; break; @@ -230,7 +230,7 @@ public class ActionBarHandler { } DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Request request = new DownloadManager.Request( - Uri.parse(streams[selectedStream].url)); + Uri.parse(videoStreams[selectedStream].url)); request.setDestinationUri(Uri.fromFile(new File( defaultPreferences.getString("download_path_preference", "/storage/emulated/0/NewPipe") + "/" + videoTitle + suffix))); diff --git a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java index 4ec9afbd6..8b2acea81 100644 --- a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java +++ b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java @@ -153,6 +153,17 @@ public class PlayVideoActivity extends AppCompatActivity { return true; } + @Override + public void onResume() { + super.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + videoView.pause(); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfo.java b/app/src/main/java/org/schabi/newpipe/VideoInfo.java index cb13d4cb2..5dde64184 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoInfo.java +++ b/app/src/main/java/org/schabi/newpipe/VideoInfo.java @@ -29,20 +29,29 @@ public class VideoInfo { public static final String F_MPEG_4 = "MPEG-4"; public static final String F_3GPP = "3GPP"; public static final String F_WEBM = "WebM"; + public static final String F_M4A = "m4a"; public static final int VIDEO_AVAILABLE = 0x00; public static final int VIDEO_UNAVAILABLE = 0x01; public static final int VIDEO_UNAVAILABLE_GEMA = 0x02; - public static class Stream { - public Stream(String u, String f, String r) { - url = u; format = f; resolution = r; + public static class VideoStream { + public VideoStream(String url, String format, String res) { + this.url = url; this.format = format; resolution = res; } public String url = ""; //url of the stream public String format = ""; public String resolution = ""; } + public static class AudioStream { + public AudioStream(String url, String format) { + this.url = url; this.format = format; + } + public String url = ""; + public String format = ""; + } + public String id = ""; public String uploader = ""; public String upload_date = ""; @@ -59,7 +68,8 @@ public class VideoInfo { public String like_count = ""; public String dislike_count = ""; public String average_rating = ""; - public Stream[] streams = null; + public VideoStream[] videoStreams = null; + public AudioStream[] audioStreams = null; public VideoInfoItem nextVideo = null; public Vector relatedVideos = null; public int videoAvailableStatus = VIDEO_AVAILABLE; diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index 558bd2569..3da274d6b 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -195,13 +195,13 @@ public class VideoItemDetailFragment extends Fragment { ActionBarHandler.getHandler().setVideoInfo(info.webpage_url, info.title); // parse streams - Vector streamsToUse = new Vector<>(); - for (VideoInfo.Stream i : info.streams) { + Vector streamsToUse = new Vector<>(); + for (VideoInfo.VideoStream i : info.videoStreams) { if (useStream(i, streamsToUse)) { streamsToUse.add(i); } } - VideoInfo.Stream[] streamList = new VideoInfo.Stream[streamsToUse.size()]; + VideoInfo.VideoStream[] streamList = new VideoInfo.VideoStream[streamsToUse.size()]; for (int i = 0; i < streamList.length; i++) { streamList[i] = streamsToUse.get(i); } @@ -227,8 +227,8 @@ public class VideoItemDetailFragment extends Fragment { } } - private boolean useStream(VideoInfo.Stream stream, Vector streams) { - for(VideoInfo.Stream i : streams) { + private boolean useStream(VideoInfo.VideoStream stream, Vector streams) { + for(VideoInfo.VideoStream i : streams) { if(i.resolution.equals(stream.resolution)) { return false; } diff --git a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java index 2046bcfef..acaf8aff9 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -55,6 +55,7 @@ public class YoutubeExtractor implements Extractor { public static String resolveFormat(int itag) { switch(itag) { + // video case 17: return VideoInfo.F_3GPP; case 18: return VideoInfo.F_MPEG_4; case 22: return VideoInfo.F_MPEG_4; @@ -185,7 +186,7 @@ public class YoutubeExtractor implements Extractor { // extract stream url //------------------------------------ String encoded_url_map = playerArgs.getString("url_encoded_fmt_stream_map"); - Vector streams = new Vector<>(); + Vector videoStreams = new Vector<>(); for(String url_data_str : encoded_url_map.split(",")) { Map tags = new HashMap<>(); for(String raw_tag : Parser.unescapeEntities(url_data_str, true).split("&")) { @@ -196,7 +197,7 @@ public class YoutubeExtractor implements Extractor { int itag = Integer.parseInt(tags.get("itag")); String streamUrl = terrible_unescape_workaround_fuck(tags.get("url")); - // if video has a signature decrypt it and add it to the url + // if video has a signature: decrypt it and add it to the url if(tags.get("s") != null) { String playerUrl = ytAssets.getString("js"); if(playerUrl.startsWith("//")) { @@ -209,15 +210,15 @@ public class YoutubeExtractor implements Extractor { } if(resolveFormat(itag) != null) { - streams.add(new VideoInfo.Stream( - streamUrl, //sometimes i have no idea what im programming -.- + videoStreams.add(new VideoInfo.VideoStream( + streamUrl, resolveFormat(itag), resolveResolutionString(itag))); } } - videoInfo.streams = new VideoInfo.Stream[streams.size()]; - for(int i = 0; i < streams.size(); i++) { - videoInfo.streams[i] = streams.get(i); + videoInfo.videoStreams = new VideoInfo.VideoStream[videoStreams.size()]; + for(int i = 0; i < videoStreams.size(); i++) { + videoInfo.videoStreams[i] = videoStreams.get(i); } } catch (Exception e) {