Skip to content

Commit 1ab5872

Browse files
committed
made player pause when screen is locked. started creating audiosupport
1 parent 2489c6c commit 1ab5872

5 files changed

Lines changed: 46 additions & 24 deletions

File tree

app/src/main/java/org/schabi/newpipe/ActionBarHandler.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class ActionBarHandler {
4949
private Context context = null;
5050
private String webisteUrl = "";
5151
private AppCompatActivity activity;
52-
private VideoInfo.Stream[] streams = null;
52+
private VideoInfo.VideoStream[] videoStreams = null;
5353
private int selectedStream = -1;
5454
private String videoTitle = "";
5555

@@ -75,8 +75,8 @@ public void setupNavMenu(AppCompatActivity activity) {
7575
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
7676
}
7777

78-
public void setStreams(VideoInfo.Stream[] streams) {
79-
this.streams = streams;
78+
public void setStreams(VideoInfo.VideoStream[] streams) {
79+
this.videoStreams = streams;
8080
selectedStream = 0;
8181
String[] itemArray = new String[streams.length];
8282
String defaultResolution = defaultPreferences
@@ -178,8 +178,8 @@ public void playVideo() {
178178
Intent intent = new Intent();
179179
try {
180180
intent.setAction(Intent.ACTION_VIEW);
181-
intent.setDataAndType(Uri.parse(streams[selectedStream].url),
182-
"video/" + streams[selectedStream].format);
181+
intent.setDataAndType(Uri.parse(videoStreams[selectedStream].url),
182+
"video/" + videoStreams[selectedStream].format);
183183
context.startActivity(intent); // HERE !!!
184184
} catch (Exception e) {
185185
e.printStackTrace();
@@ -205,7 +205,7 @@ public void onClick(DialogInterface dialog, int which) {
205205
} else {
206206
Intent intent = new Intent(context, PlayVideoActivity.class);
207207
intent.putExtra(PlayVideoActivity.VIDEO_TITLE, videoTitle);
208-
intent.putExtra(PlayVideoActivity.STREAM_URL, streams[selectedStream].url);
208+
intent.putExtra(PlayVideoActivity.STREAM_URL, videoStreams[selectedStream].url);
209209
intent.putExtra(PlayVideoActivity.VIDEO_URL, webisteUrl);
210210
context.startActivity(intent);
211211
}
@@ -217,7 +217,7 @@ public void downloadVideo() {
217217
Log.d(TAG, "bla");
218218
if(!videoTitle.isEmpty()) {
219219
String suffix = "";
220-
switch (streams[selectedStream].format) {
220+
switch (videoStreams[selectedStream].format) {
221221
case VideoInfo.F_WEBM:
222222
suffix = ".webm";
223223
break;
@@ -230,7 +230,7 @@ public void downloadVideo() {
230230
}
231231
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
232232
DownloadManager.Request request = new DownloadManager.Request(
233-
Uri.parse(streams[selectedStream].url));
233+
Uri.parse(videoStreams[selectedStream].url));
234234
request.setDestinationUri(Uri.fromFile(new File(
235235
defaultPreferences.getString("download_path_preference", "/storage/emulated/0/NewPipe")
236236
+ "/" + videoTitle + suffix)));

app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ public boolean onCreatePanelMenu(int featured, Menu menu) {
153153
return true;
154154
}
155155

156+
@Override
157+
public void onResume() {
158+
super.onResume();
159+
}
160+
161+
@Override
162+
public void onPause() {
163+
super.onPause();
164+
videoView.pause();
165+
}
166+
156167
@Override
157168
public boolean onOptionsItemSelected(MenuItem item) {
158169
int id = item.getItemId();

app/src/main/java/org/schabi/newpipe/VideoInfo.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,29 @@ public class VideoInfo {
2929
public static final String F_MPEG_4 = "MPEG-4";
3030
public static final String F_3GPP = "3GPP";
3131
public static final String F_WEBM = "WebM";
32+
public static final String F_M4A = "m4a";
3233

3334
public static final int VIDEO_AVAILABLE = 0x00;
3435
public static final int VIDEO_UNAVAILABLE = 0x01;
3536
public static final int VIDEO_UNAVAILABLE_GEMA = 0x02;
3637

37-
public static class Stream {
38-
public Stream(String u, String f, String r) {
39-
url = u; format = f; resolution = r;
38+
public static class VideoStream {
39+
public VideoStream(String url, String format, String res) {
40+
this.url = url; this.format = format; resolution = res;
4041
}
4142
public String url = ""; //url of the stream
4243
public String format = "";
4344
public String resolution = "";
4445
}
4546

47+
public static class AudioStream {
48+
public AudioStream(String url, String format) {
49+
this.url = url; this.format = format;
50+
}
51+
public String url = "";
52+
public String format = "";
53+
}
54+
4655
public String id = "";
4756
public String uploader = "";
4857
public String upload_date = "";
@@ -59,7 +68,8 @@ public Stream(String u, String f, String r) {
5968
public String like_count = "";
6069
public String dislike_count = "";
6170
public String average_rating = "";
62-
public Stream[] streams = null;
71+
public VideoStream[] videoStreams = null;
72+
public AudioStream[] audioStreams = null;
6373
public VideoInfoItem nextVideo = null;
6474
public Vector<VideoInfoItem> relatedVideos = null;
6575
public int videoAvailableStatus = VIDEO_AVAILABLE;

app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ public void updateInfo(VideoInfo info) {
195195
ActionBarHandler.getHandler().setVideoInfo(info.webpage_url, info.title);
196196

197197
// parse streams
198-
Vector<VideoInfo.Stream> streamsToUse = new Vector<>();
199-
for (VideoInfo.Stream i : info.streams) {
198+
Vector<VideoInfo.VideoStream> streamsToUse = new Vector<>();
199+
for (VideoInfo.VideoStream i : info.videoStreams) {
200200
if (useStream(i, streamsToUse)) {
201201
streamsToUse.add(i);
202202
}
203203
}
204-
VideoInfo.Stream[] streamList = new VideoInfo.Stream[streamsToUse.size()];
204+
VideoInfo.VideoStream[] streamList = new VideoInfo.VideoStream[streamsToUse.size()];
205205
for (int i = 0; i < streamList.length; i++) {
206206
streamList[i] = streamsToUse.get(i);
207207
}
@@ -227,8 +227,8 @@ public void updateInfo(VideoInfo info) {
227227
}
228228
}
229229

230-
private boolean useStream(VideoInfo.Stream stream, Vector<VideoInfo.Stream> streams) {
231-
for(VideoInfo.Stream i : streams) {
230+
private boolean useStream(VideoInfo.VideoStream stream, Vector<VideoInfo.VideoStream> streams) {
231+
for(VideoInfo.VideoStream i : streams) {
232232
if(i.resolution.equals(stream.resolution)) {
233233
return false;
234234
}

app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class YoutubeExtractor implements Extractor {
5555

5656
public static String resolveFormat(int itag) {
5757
switch(itag) {
58+
// video
5859
case 17: return VideoInfo.F_3GPP;
5960
case 18: return VideoInfo.F_MPEG_4;
6061
case 22: return VideoInfo.F_MPEG_4;
@@ -185,7 +186,7 @@ public VideoInfo getVideoInfo(String siteUrl) {
185186
// extract stream url
186187
//------------------------------------
187188
String encoded_url_map = playerArgs.getString("url_encoded_fmt_stream_map");
188-
Vector<VideoInfo.Stream> streams = new Vector<>();
189+
Vector<VideoInfo.VideoStream> videoStreams = new Vector<>();
189190
for(String url_data_str : encoded_url_map.split(",")) {
190191
Map<String, String> tags = new HashMap<>();
191192
for(String raw_tag : Parser.unescapeEntities(url_data_str, true).split("&")) {
@@ -196,7 +197,7 @@ public VideoInfo getVideoInfo(String siteUrl) {
196197
int itag = Integer.parseInt(tags.get("itag"));
197198
String streamUrl = terrible_unescape_workaround_fuck(tags.get("url"));
198199

199-
// if video has a signature decrypt it and add it to the url
200+
// if video has a signature: decrypt it and add it to the url
200201
if(tags.get("s") != null) {
201202
String playerUrl = ytAssets.getString("js");
202203
if(playerUrl.startsWith("//")) {
@@ -209,15 +210,15 @@ public VideoInfo getVideoInfo(String siteUrl) {
209210
}
210211

211212
if(resolveFormat(itag) != null) {
212-
streams.add(new VideoInfo.Stream(
213-
streamUrl, //sometimes i have no idea what im programming -.-
213+
videoStreams.add(new VideoInfo.VideoStream(
214+
streamUrl,
214215
resolveFormat(itag),
215216
resolveResolutionString(itag)));
216217
}
217218
}
218-
videoInfo.streams = new VideoInfo.Stream[streams.size()];
219-
for(int i = 0; i < streams.size(); i++) {
220-
videoInfo.streams[i] = streams.get(i);
219+
videoInfo.videoStreams = new VideoInfo.VideoStream[videoStreams.size()];
220+
for(int i = 0; i < videoStreams.size(); i++) {
221+
videoInfo.videoStreams[i] = videoStreams.get(i);
221222
}
222223

223224
} catch (Exception e) {

0 commit comments

Comments
 (0)