diff --git a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java index 6e70e07ba..a5e7c8cff 100644 --- a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java +++ b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java @@ -19,6 +19,8 @@ import android.widget.ArrayAdapter; import org.schabi.newpipe.crawler.MediaFormat; import org.schabi.newpipe.crawler.VideoInfo; +import java.util.List; + /** * Created by Christian Schabesberger on 18.08.15. * @@ -49,7 +51,7 @@ class ActionBarHandler { private Bitmap videoThumbnail = null; private String channelName = ""; private AppCompatActivity activity; - private VideoInfo.VideoStream[] videoStreams = null; + private List videoStreams = null; private VideoInfo.AudioStream audioStream = null; private int selectedStream = -1; private String videoTitle = ""; @@ -93,19 +95,21 @@ class ActionBarHandler { } @SuppressWarnings("deprecation") - public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStream[] audioStreams) { + public void setStreams(List videoStreams, + List audioStreams) { this.videoStreams = videoStreams; selectedStream = 0; defaultPreferences = PreferenceManager.getDefaultSharedPreferences(activity); - String[] itemArray = new String[videoStreams.length]; + String[] itemArray = new String[videoStreams.size()]; String defaultResolution = defaultPreferences .getString(activity.getString(R.string.default_resolution_key), activity.getString(R.string.default_resolution_value)); int defaultResolutionPos = 0; - for(int i = 0; i < videoStreams.length; i++) { - itemArray[i] = MediaFormat.getNameById(videoStreams[i].format) + " " + videoStreams[i].resolution; - if(defaultResolution.equals(videoStreams[i].resolution)) { + for(int i = 0; i < videoStreams.size(); i++) { + VideoInfo.VideoStream item = videoStreams.get(i); + itemArray[i] = MediaFormat.getNameById(item.format) + " " + item.resolution; + if(defaultResolution.equals(item.resolution)) { defaultResolutionPos = i; } } @@ -209,6 +213,8 @@ class ActionBarHandler { public void playVideo() { // ----------- THE MAGIC MOMENT --------------- if(!videoTitle.isEmpty()) { + VideoInfo.VideoStream selectedStreamItem = videoStreams.get(selectedStream); + if (PreferenceManager.getDefaultSharedPreferences(activity) .getBoolean(activity.getString(R.string.use_external_video_player_key), false)) { @@ -217,8 +223,8 @@ class ActionBarHandler { try { intent.setAction(Intent.ACTION_VIEW); - intent.setDataAndType(Uri.parse(videoStreams[selectedStream].url), - MediaFormat.getMimeById(videoStreams[selectedStream].format)); + intent.setDataAndType(Uri.parse(selectedStreamItem.url), + MediaFormat.getMimeById(selectedStreamItem.format)); intent.putExtra(Intent.EXTRA_TITLE, videoTitle); intent.putExtra("title", videoTitle); @@ -248,7 +254,7 @@ class ActionBarHandler { // Internal Player Intent intent = new Intent(activity, PlayVideoActivity.class); intent.putExtra(PlayVideoActivity.VIDEO_TITLE, videoTitle); - intent.putExtra(PlayVideoActivity.STREAM_URL, videoStreams[selectedStream].url); + intent.putExtra(PlayVideoActivity.STREAM_URL, selectedStreamItem.url); intent.putExtra(PlayVideoActivity.VIDEO_URL, websiteUrl); intent.putExtra(PlayVideoActivity.START_POSITION, startPosition); activity.startActivity(intent); //also HERE !!! @@ -264,13 +270,14 @@ class ActionBarHandler { private void downloadVideo() { if(!videoTitle.isEmpty()) { - String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format); + VideoInfo.VideoStream selectedStreamItem = videoStreams.get(selectedStream); + String videoSuffix = "." + MediaFormat.getSuffixById(selectedStreamItem.format); String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format); Bundle args = new Bundle(); args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix); args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix); args.putString(DownloadDialog.TITLE, videoTitle); - args.putString(DownloadDialog.VIDEO_URL, videoStreams[selectedStream].url); + args.putString(DownloadDialog.VIDEO_URL, selectedStreamItem.url); args.putString(DownloadDialog.AUDIO_URL, audioStream.url); DownloadDialog downloadDialog = new DownloadDialog(); downloadDialog.setArguments(args); diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index f45cff230..daa7719c0 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -302,11 +302,8 @@ public class VideoItemDetailFragment extends Fragment { streamsToUse.add(i); } } - VideoInfo.VideoStream[] streamList = new VideoInfo.VideoStream[streamsToUse.size()]; - for (int i = 0; i < streamList.length; i++) { - streamList[i] = streamsToUse.get(i); - } - actionBarHandler.setStreams(streamList, info.audioStreams); + + actionBarHandler.setStreams(streamsToUse, info.audioStreams); nextVideoButton.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/org/schabi/newpipe/crawler/DashMpdParser.java b/app/src/main/java/org/schabi/newpipe/crawler/DashMpdParser.java index b893599dd..027cc66a5 100644 --- a/app/src/main/java/org/schabi/newpipe/crawler/DashMpdParser.java +++ b/app/src/main/java/org/schabi/newpipe/crawler/DashMpdParser.java @@ -6,6 +6,7 @@ import org.xmlpull.v1.XmlPullParser; import java.io.IOException; import java.io.StringReader; +import java.util.List; import java.util.Vector; /** @@ -36,7 +37,7 @@ public class DashMpdParser { } } - public static VideoInfo.AudioStream[] getAudioStreams(String dashManifestUrl, + public static List getAudioStreams(String dashManifestUrl, Downloader downloader) throws DashMpdParsingException { String dashDoc; @@ -96,6 +97,6 @@ public class DashMpdParser { } catch(Exception e) { throw new DashMpdParsingException("Could not parse Dash mpd", e); } - return audioStreams.toArray(new VideoInfo.AudioStream[audioStreams.size()]); + return audioStreams; } } diff --git a/app/src/main/java/org/schabi/newpipe/crawler/SearchEngine.java b/app/src/main/java/org/schabi/newpipe/crawler/SearchEngine.java index 686dea912..845c78926 100644 --- a/app/src/main/java/org/schabi/newpipe/crawler/SearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/crawler/SearchEngine.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.crawler; import java.io.IOException; import java.util.ArrayList; +import java.util.List; import java.util.Vector; /** @@ -29,7 +30,7 @@ public interface SearchEngine { class Result { public String errorMessage = ""; public String suggestion = ""; - public final Vector resultList = new Vector<>(); + public final List resultList = new Vector<>(); } ArrayList suggestionList(String query, Downloader dl) diff --git a/app/src/main/java/org/schabi/newpipe/crawler/VideoExtractor.java b/app/src/main/java/org/schabi/newpipe/crawler/VideoExtractor.java index eb336b5ae..44b4e743d 100644 --- a/app/src/main/java/org/schabi/newpipe/crawler/VideoExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/crawler/VideoExtractor.java @@ -20,7 +20,7 @@ package org.schabi.newpipe.crawler; * along with NewPipe. If not, see . */ -import java.util.Vector; +import java.util.List; /**Scrapes information from a video streaming service (eg, YouTube).*/ @@ -63,15 +63,15 @@ public interface VideoExtractor { public abstract String getUploadDate() throws ParsingException; public abstract String getThumbnailUrl() throws ParsingException; public abstract String getUploaderThumbnailUrl() throws ParsingException; - public abstract VideoInfo.AudioStream[] getAudioStreams() throws ParsingException; - public abstract VideoInfo.VideoStream[] getVideoStreams() throws ParsingException; + public abstract List getAudioStreams() throws ParsingException; + public abstract List getVideoStreams() throws ParsingException; public abstract String getDashMpdUrl() throws ParsingException; public abstract int getAgeLimit() throws ParsingException; public abstract String getAverageRating() throws ParsingException; public abstract int getLikeCount() throws ParsingException; public abstract int getDislikeCount() throws ParsingException; public abstract VideoPreviewInfo getNextVideo() throws ParsingException; - public abstract Vector getRelatedVideos() throws ParsingException; + public abstract List getRelatedVideos() throws ParsingException; public abstract VideoUrlIdHandler getUrlIdConverter(); public abstract String getPageUrl(); } diff --git a/app/src/main/java/org/schabi/newpipe/crawler/VideoInfo.java b/app/src/main/java/org/schabi/newpipe/crawler/VideoInfo.java index d5f10553f..2542c501d 100644 --- a/app/src/main/java/org/schabi/newpipe/crawler/VideoInfo.java +++ b/app/src/main/java/org/schabi/newpipe/crawler/VideoInfo.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.crawler; import java.io.IOException; import java.util.List; +import java.util.Vector; /** * Created by Christian Schabesberger on 26.08.15. @@ -48,10 +49,11 @@ public class VideoInfo extends AbstractVideoInfo { /** Load and extract audio*/ videoInfo.audioStreams = extractor.getAudioStreams(); if(videoInfo.dashMpdUrl != null && !videoInfo.dashMpdUrl.isEmpty()) { - if(videoInfo.audioStreams == null || videoInfo.audioStreams.length == 0) { - videoInfo.audioStreams = - DashMpdParser.getAudioStreams(videoInfo.dashMpdUrl, downloader); + if(videoInfo.audioStreams == null) { + videoInfo.audioStreams = new Vector(); } + videoInfo.audioStreams.addAll( + DashMpdParser.getAudioStreams(videoInfo.dashMpdUrl, downloader)); } /** Extract video stream url*/ videoInfo.videoStreams = extractor.getVideoStreams(); @@ -73,8 +75,8 @@ public class VideoInfo extends AbstractVideoInfo { public String uploader_thumbnail_url = ""; public String description = ""; /*todo: make this lists over vectors*/ - public VideoStream[] videoStreams = null; - public AudioStream[] audioStreams = null; + public List videoStreams = null; + public List audioStreams = null; // video streams provided by the dash mpd do not need to be provided as VideoStream. // Later on this will also aplly to audio streams. Since dash mpd is standarized, // crawling such a file is not service dependent. Therefore getting audio only streams by yust diff --git a/app/src/main/java/org/schabi/newpipe/crawler/services/youtube/YoutubeVideoExtractor.java b/app/src/main/java/org/schabi/newpipe/crawler/services/youtube/YoutubeVideoExtractor.java index 744afd48c..07d2b23a7 100644 --- a/app/src/main/java/org/schabi/newpipe/crawler/services/youtube/YoutubeVideoExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/crawler/services/youtube/YoutubeVideoExtractor.java @@ -24,6 +24,7 @@ import org.schabi.newpipe.crawler.VideoPreviewInfo; import java.io.IOException; import java.net.URLDecoder; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Vector; @@ -251,13 +252,13 @@ public class YoutubeVideoExtractor implements VideoExtractor { } @Override - public VideoInfo.AudioStream[] getAudioStreams() throws ParsingException { + public List getAudioStreams() throws ParsingException { /* If we provide a valid dash manifest, we don't need to provide audio streams extra */ return null; } @Override - public VideoInfo.VideoStream[] getVideoStreams() throws ParsingException { + public List getVideoStreams() throws ParsingException { Vector videoStreams = new Vector<>(); try{ String encoded_url_map = playerArgs.getString("url_encoded_fmt_stream_map"); @@ -298,7 +299,7 @@ public class YoutubeVideoExtractor implements VideoExtractor { throw new ParsingException("Failed to get any video stream"); } - return videoStreams.toArray(new VideoInfo.VideoStream[videoStreams.size()]); + return videoStreams; } /**Attempts to parse (and return) the offset to start playing the video from.