1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 02:53:09 +01:00

made player pause when screen is locked. started creating audiosupport

This commit is contained in:
Christian Schabesberger 2015-09-21 13:32:11 +02:00
parent 2489c6c329
commit 1ab5872857
5 changed files with 46 additions and 24 deletions

View File

@ -49,7 +49,7 @@ public class ActionBarHandler {
private Context context = null; private Context context = null;
private String webisteUrl = ""; private String webisteUrl = "";
private AppCompatActivity activity; private AppCompatActivity activity;
private VideoInfo.Stream[] streams = null; private VideoInfo.VideoStream[] videoStreams = null;
private int selectedStream = -1; private int selectedStream = -1;
private String videoTitle = ""; private String videoTitle = "";
@ -75,8 +75,8 @@ public class ActionBarHandler {
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
} }
public void setStreams(VideoInfo.Stream[] streams) { public void setStreams(VideoInfo.VideoStream[] streams) {
this.streams = streams; this.videoStreams = streams;
selectedStream = 0; selectedStream = 0;
String[] itemArray = new String[streams.length]; String[] itemArray = new String[streams.length];
String defaultResolution = defaultPreferences String defaultResolution = defaultPreferences
@ -178,8 +178,8 @@ public class ActionBarHandler {
Intent intent = new Intent(); Intent intent = new Intent();
try { try {
intent.setAction(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(streams[selectedStream].url), intent.setDataAndType(Uri.parse(videoStreams[selectedStream].url),
"video/" + streams[selectedStream].format); "video/" + videoStreams[selectedStream].format);
context.startActivity(intent); // HERE !!! context.startActivity(intent); // HERE !!!
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -205,7 +205,7 @@ public class ActionBarHandler {
} else { } else {
Intent intent = new Intent(context, PlayVideoActivity.class); Intent intent = new Intent(context, PlayVideoActivity.class);
intent.putExtra(PlayVideoActivity.VIDEO_TITLE, videoTitle); 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); intent.putExtra(PlayVideoActivity.VIDEO_URL, webisteUrl);
context.startActivity(intent); context.startActivity(intent);
} }
@ -217,7 +217,7 @@ public class ActionBarHandler {
Log.d(TAG, "bla"); Log.d(TAG, "bla");
if(!videoTitle.isEmpty()) { if(!videoTitle.isEmpty()) {
String suffix = ""; String suffix = "";
switch (streams[selectedStream].format) { switch (videoStreams[selectedStream].format) {
case VideoInfo.F_WEBM: case VideoInfo.F_WEBM:
suffix = ".webm"; suffix = ".webm";
break; break;
@ -230,7 +230,7 @@ public class ActionBarHandler {
} }
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request( DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(streams[selectedStream].url)); Uri.parse(videoStreams[selectedStream].url));
request.setDestinationUri(Uri.fromFile(new File( request.setDestinationUri(Uri.fromFile(new File(
defaultPreferences.getString("download_path_preference", "/storage/emulated/0/NewPipe") defaultPreferences.getString("download_path_preference", "/storage/emulated/0/NewPipe")
+ "/" + videoTitle + suffix))); + "/" + videoTitle + suffix)));

View File

@ -153,6 +153,17 @@ public class PlayVideoActivity extends AppCompatActivity {
return true; return true;
} }
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
videoView.pause();
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId(); int id = item.getItemId();

View File

@ -29,20 +29,29 @@ public class VideoInfo {
public static final String F_MPEG_4 = "MPEG-4"; public static final String F_MPEG_4 = "MPEG-4";
public static final String F_3GPP = "3GPP"; public static final String F_3GPP = "3GPP";
public static final String F_WEBM = "WebM"; 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_AVAILABLE = 0x00;
public static final int VIDEO_UNAVAILABLE = 0x01; public static final int VIDEO_UNAVAILABLE = 0x01;
public static final int VIDEO_UNAVAILABLE_GEMA = 0x02; public static final int VIDEO_UNAVAILABLE_GEMA = 0x02;
public static class Stream { public static class VideoStream {
public Stream(String u, String f, String r) { public VideoStream(String url, String format, String res) {
url = u; format = f; resolution = r; this.url = url; this.format = format; resolution = res;
} }
public String url = ""; //url of the stream public String url = ""; //url of the stream
public String format = ""; public String format = "";
public String resolution = ""; 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 id = "";
public String uploader = ""; public String uploader = "";
public String upload_date = ""; public String upload_date = "";
@ -59,7 +68,8 @@ public class VideoInfo {
public String like_count = ""; public String like_count = "";
public String dislike_count = ""; public String dislike_count = "";
public String average_rating = ""; public String average_rating = "";
public Stream[] streams = null; public VideoStream[] videoStreams = null;
public AudioStream[] audioStreams = null;
public VideoInfoItem nextVideo = null; public VideoInfoItem nextVideo = null;
public Vector<VideoInfoItem> relatedVideos = null; public Vector<VideoInfoItem> relatedVideos = null;
public int videoAvailableStatus = VIDEO_AVAILABLE; public int videoAvailableStatus = VIDEO_AVAILABLE;

View File

@ -195,13 +195,13 @@ public class VideoItemDetailFragment extends Fragment {
ActionBarHandler.getHandler().setVideoInfo(info.webpage_url, info.title); ActionBarHandler.getHandler().setVideoInfo(info.webpage_url, info.title);
// parse streams // parse streams
Vector<VideoInfo.Stream> streamsToUse = new Vector<>(); Vector<VideoInfo.VideoStream> streamsToUse = new Vector<>();
for (VideoInfo.Stream i : info.streams) { for (VideoInfo.VideoStream i : info.videoStreams) {
if (useStream(i, streamsToUse)) { if (useStream(i, streamsToUse)) {
streamsToUse.add(i); 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++) { for (int i = 0; i < streamList.length; i++) {
streamList[i] = streamsToUse.get(i); streamList[i] = streamsToUse.get(i);
} }
@ -227,8 +227,8 @@ public class VideoItemDetailFragment extends Fragment {
} }
} }
private boolean useStream(VideoInfo.Stream stream, Vector<VideoInfo.Stream> streams) { private boolean useStream(VideoInfo.VideoStream stream, Vector<VideoInfo.VideoStream> streams) {
for(VideoInfo.Stream i : streams) { for(VideoInfo.VideoStream i : streams) {
if(i.resolution.equals(stream.resolution)) { if(i.resolution.equals(stream.resolution)) {
return false; return false;
} }

View File

@ -55,6 +55,7 @@ public class YoutubeExtractor implements Extractor {
public static String resolveFormat(int itag) { public static String resolveFormat(int itag) {
switch(itag) { switch(itag) {
// video
case 17: return VideoInfo.F_3GPP; case 17: return VideoInfo.F_3GPP;
case 18: return VideoInfo.F_MPEG_4; case 18: return VideoInfo.F_MPEG_4;
case 22: return VideoInfo.F_MPEG_4; case 22: return VideoInfo.F_MPEG_4;
@ -185,7 +186,7 @@ public class YoutubeExtractor implements Extractor {
// extract stream url // extract stream url
//------------------------------------ //------------------------------------
String encoded_url_map = playerArgs.getString("url_encoded_fmt_stream_map"); String encoded_url_map = playerArgs.getString("url_encoded_fmt_stream_map");
Vector<VideoInfo.Stream> streams = new Vector<>(); Vector<VideoInfo.VideoStream> videoStreams = new Vector<>();
for(String url_data_str : encoded_url_map.split(",")) { for(String url_data_str : encoded_url_map.split(",")) {
Map<String, String> tags = new HashMap<>(); Map<String, String> tags = new HashMap<>();
for(String raw_tag : Parser.unescapeEntities(url_data_str, true).split("&")) { 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")); int itag = Integer.parseInt(tags.get("itag"));
String streamUrl = terrible_unescape_workaround_fuck(tags.get("url")); 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) { if(tags.get("s") != null) {
String playerUrl = ytAssets.getString("js"); String playerUrl = ytAssets.getString("js");
if(playerUrl.startsWith("//")) { if(playerUrl.startsWith("//")) {
@ -209,15 +210,15 @@ public class YoutubeExtractor implements Extractor {
} }
if(resolveFormat(itag) != null) { if(resolveFormat(itag) != null) {
streams.add(new VideoInfo.Stream( videoStreams.add(new VideoInfo.VideoStream(
streamUrl, //sometimes i have no idea what im programming -.- streamUrl,
resolveFormat(itag), resolveFormat(itag),
resolveResolutionString(itag))); resolveResolutionString(itag)));
} }
} }
videoInfo.streams = new VideoInfo.Stream[streams.size()]; videoInfo.videoStreams = new VideoInfo.VideoStream[videoStreams.size()];
for(int i = 0; i < streams.size(); i++) { for(int i = 0; i < videoStreams.size(); i++) {
videoInfo.streams[i] = streams.get(i); videoInfo.videoStreams[i] = videoStreams.get(i);
} }
} catch (Exception e) { } catch (Exception e) {