made player pause when screen is locked. started creating audiosupport
This commit is contained in:
parent
2489c6c329
commit
1ab5872857
|
@ -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)));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<VideoInfoItem> relatedVideos = null;
|
||||
public int videoAvailableStatus = VIDEO_AVAILABLE;
|
||||
|
|
|
@ -195,13 +195,13 @@ public class VideoItemDetailFragment extends Fragment {
|
|||
ActionBarHandler.getHandler().setVideoInfo(info.webpage_url, info.title);
|
||||
|
||||
// parse streams
|
||||
Vector<VideoInfo.Stream> streamsToUse = new Vector<>();
|
||||
for (VideoInfo.Stream i : info.streams) {
|
||||
Vector<VideoInfo.VideoStream> 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<VideoInfo.Stream> streams) {
|
||||
for(VideoInfo.Stream i : streams) {
|
||||
private boolean useStream(VideoInfo.VideoStream stream, Vector<VideoInfo.VideoStream> streams) {
|
||||
for(VideoInfo.VideoStream i : streams) {
|
||||
if(i.resolution.equals(stream.resolution)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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<VideoInfo.Stream> streams = new Vector<>();
|
||||
Vector<VideoInfo.VideoStream> videoStreams = new Vector<>();
|
||||
for(String url_data_str : encoded_url_map.split(",")) {
|
||||
Map<String, String> 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) {
|
||||
|
|
Loading…
Reference in New Issue