Skip to content

Commit 2fc2fa5

Browse files
committed
refactoring VideoInfo & MediaFormat, part 2:
* fixed errors caused by moving media format code to MediaFormat enum
1 parent c874585 commit 2fc2fa5

3 files changed

Lines changed: 28 additions & 28 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
@@ -77,7 +77,7 @@ public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStre
7777
int defaultResolutionPos = 0;
7878

7979
for(int i = 0; i < videoStreams.length; i++) {
80-
itemArray[i] = VideoInfo.getNameById(videoStreams[i].format) + " " + videoStreams[i].resolution;
80+
itemArray[i] = MediaFormat.getNameById(videoStreams[i].format) + " " + videoStreams[i].resolution;
8181
if(defaultResolution.equals(videoStreams[i].resolution)) {
8282
defaultResolutionPos = i;
8383
}
@@ -98,14 +98,14 @@ public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStre
9898
.getString(activity.getString(R.string.defaultAudioFormatPreference), "webm");
9999
if(preferedFormat.equals("webm")) {
100100
for(VideoInfo.AudioStream s : audioStreams) {
101-
if(s.format == VideoInfo.I_WEBMA) {
101+
if(s.format == MediaFormat.WEBMA.id) {
102102
audioStream = s;
103103
}
104104
}
105105
} else if(preferedFormat.equals("m4a")){
106106
for(VideoInfo.AudioStream s : audioStreams) {
107-
Log.d(TAG, VideoInfo.getMimeById(s.format) + " : " + Integer.toString(s.bandwidth));
108-
if(s.format == VideoInfo.I_M4A &&
107+
Log.d(TAG, MediaFormat.getMimeById(s.format) + " : " + Integer.toString(s.bandwidth));
108+
if(s.format == MediaFormat.M4A.id &&
109109
(audioStream == null || audioStream.bandwidth > s.bandwidth)) {
110110
audioStream = s;
111111
Log.d(TAG, "last choosen");
@@ -196,7 +196,7 @@ public void playVideo() {
196196
intent.setAction(Intent.ACTION_VIEW);
197197

198198
intent.setDataAndType(Uri.parse(videoStreams[selectedStream].url),
199-
VideoInfo.getMimeById(videoStreams[selectedStream].format));
199+
MediaFormat.getMimeById(videoStreams[selectedStream].format));
200200
intent.putExtra(Intent.EXTRA_TITLE, videoTitle);
201201
intent.putExtra("title", videoTitle);
202202

@@ -237,8 +237,8 @@ public void onClick(DialogInterface dialog, int which) {
237237
public void downloadVideo() {
238238
Log.d(TAG, "bla");
239239
if(!videoTitle.isEmpty()) {
240-
String videoSuffix = "." + VideoInfo.getSuffixById(videoStreams[selectedStream].format);
241-
String audioSuffix = "." + VideoInfo.getSuffixById(audioStream.format);
240+
String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format);
241+
String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
242242
Bundle args = new Bundle();
243243
args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix);
244244
args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix);
@@ -297,7 +297,7 @@ public void playAudio() {
297297
try {
298298
intent.setAction(Intent.ACTION_VIEW);
299299
intent.setDataAndType(Uri.parse(audioStream.url),
300-
VideoInfo.getMimeById(audioStream.format));
300+
MediaFormat.getMimeById(audioStream.format));
301301
intent.putExtra(Intent.EXTRA_TITLE, videoTitle);
302302
intent.putExtra("title", videoTitle);
303303
activity.startActivity(intent); // HERE !!!

app/src/main/java/org/schabi/newpipe/VideoFormat.java renamed to app/src/main/java/org/schabi/newpipe/MediaFormat.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Created by scc on 08/11/15.
55
*/
6-
public enum VideoFormat {
6+
public enum MediaFormat {
77
// id name suffix mime type
88
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
99
v3GPP (0x1, "3GPP", "3gp", "video/3gpp"),
@@ -16,29 +16,29 @@ public enum VideoFormat {
1616
public final String suffix;
1717
public final String mimeType;
1818

19-
VideoFormat(int id, String name, String suffix, String mimeType) {
19+
MediaFormat(int id, String name, String suffix, String mimeType) {
2020
this.id = id;
2121
this.name = name;
2222
this.suffix = suffix;
2323
this.mimeType = mimeType;
2424
}
2525

2626
public static String getNameById(int ident) {
27-
for (VideoFormat vf : VideoFormat.values()) {
27+
for (MediaFormat vf : MediaFormat.values()) {
2828
if(vf.id == ident) return vf.name;
2929
}
3030
return "";
3131
}
3232

3333
public static String getSuffixById(int ident) {
34-
for (VideoFormat vf : VideoFormat.values()) {
34+
for (MediaFormat vf : MediaFormat.values()) {
3535
if(vf.id == ident) return vf.suffix;
3636
}
3737
return "";
3838
}
3939

4040
public static String getMimeById(int ident) {
41-
for (VideoFormat vf : VideoFormat.values()) {
41+
for (MediaFormat vf : MediaFormat.values()) {
4242
if(vf.id == ident) return vf.mimeType;
4343
}
4444
return "";

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.util.Log;
44
import android.util.Xml;
55

6-
import org.json.JSONException;
76
import org.json.JSONObject;
87
import org.jsoup.Jsoup;
98
import org.jsoup.nodes.Document;
@@ -14,6 +13,7 @@
1413
import org.mozilla.javascript.ScriptableObject;
1514
import org.schabi.newpipe.Downloader;
1615
import org.schabi.newpipe.Extractor;
16+
import org.schabi.newpipe.MediaFormat;
1717
import org.schabi.newpipe.VideoInfo;
1818
import org.schabi.newpipe.VideoInfoItem;
1919
import org.xmlpull.v1.XmlPullParser;
@@ -57,16 +57,16 @@ public class YoutubeExtractor implements Extractor {
5757
public static int resolveFormat(int itag) {
5858
switch(itag) {
5959
// video
60-
case 17: return VideoInfo.I_3GPP;
61-
case 18: return VideoInfo.I_MPEG_4;
62-
case 22: return VideoInfo.I_MPEG_4;
63-
case 36: return VideoInfo.I_3GPP;
64-
case 37: return VideoInfo.I_MPEG_4;
65-
case 38: return VideoInfo.I_MPEG_4;
66-
case 43: return VideoInfo.I_WEBM;
67-
case 44: return VideoInfo.I_WEBM;
68-
case 45: return VideoInfo.I_WEBM;
69-
case 46: return VideoInfo.I_WEBM;
60+
case 17: return MediaFormat.v3GPP.id;
61+
case 18: return MediaFormat.MPEG_4.id;
62+
case 22: return MediaFormat.MPEG_4.id;
63+
case 36: return MediaFormat.v3GPP.id;
64+
case 37: return MediaFormat.MPEG_4.id;
65+
case 38: return MediaFormat.MPEG_4.id;
66+
case 43: return MediaFormat.WEBM.id;
67+
case 44: return MediaFormat.WEBM.id;
68+
case 45: return MediaFormat.WEBM.id;
69+
case 46: return MediaFormat.WEBM.id;
7070
default:
7171
//Log.i(TAG, "Itag " + Integer.toString(itag) + " not known or not supported.");
7272
return -1;
@@ -344,10 +344,10 @@ private VideoInfo.AudioStream[] parseDashManifest(String dashManifest, String de
344344
if(currentTagIsBaseUrl &&
345345
(currentMimeType.contains("audio"))) {
346346
int format = -1;
347-
if(currentMimeType.equals(VideoInfo.M_WEBMA)) {
348-
format = VideoInfo.I_WEBMA;
349-
} else if(currentMimeType.equals(VideoInfo.M_M4A)) {
350-
format = VideoInfo.I_M4A;
347+
if(currentMimeType.equals(MediaFormat.WEBMA.mimeType)) {
348+
format = MediaFormat.WEBMA.id;
349+
} else if(currentMimeType.equals(MediaFormat.M4A.mimeType)) {
350+
format = MediaFormat.M4A.id;
351351
}
352352
audioStreams.add(new VideoInfo.AudioStream(parser.getText(),
353353
format, currentBandwidth, currentSamplingRate));

0 commit comments

Comments
 (0)