Skip to content

Commit d24c87c

Browse files
committed
added autio streaming & jumped to version 0.4.0
1 parent 1ab5872 commit d24c87c

13 files changed

Lines changed: 393 additions & 64 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "org.schabi.newpipe"
99
minSdkVersion 15
1010
targetSdkVersion 23
11-
versionCode 2
12-
versionName "0.3.5"
11+
versionCode 3
12+
versionName "0.4.0"
1313
}
1414
buildTypes {
1515
release {

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

Lines changed: 74 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.Intent;
77
import android.content.SharedPreferences;
88
import android.net.Uri;
9+
import android.os.Bundle;
910
import android.preference.Preference;
1011
import android.preference.PreferenceManager;
1112
import android.support.v4.view.MenuItemCompat;
@@ -50,6 +51,7 @@ public class ActionBarHandler {
5051
private String webisteUrl = "";
5152
private AppCompatActivity activity;
5253
private VideoInfo.VideoStream[] videoStreams = null;
54+
private VideoInfo.AudioStream audioStream = null;
5355
private int selectedStream = -1;
5456
private String videoTitle = "";
5557

@@ -75,18 +77,18 @@ public void setupNavMenu(AppCompatActivity activity) {
7577
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
7678
}
7779

78-
public void setStreams(VideoInfo.VideoStream[] streams) {
79-
this.videoStreams = streams;
80+
public void setStreams(VideoInfo.VideoStream[] videoStreams, VideoInfo.AudioStream[] audioStreams) {
81+
this.videoStreams = videoStreams;
8082
selectedStream = 0;
81-
String[] itemArray = new String[streams.length];
83+
String[] itemArray = new String[videoStreams.length];
8284
String defaultResolution = defaultPreferences
8385
.getString(context.getString(R.string.defaultResolutionPreference),
8486
context.getString(R.string.defaultResolutionListItem));
8587
int defaultResolutionPos = 0;
8688

87-
for(int i = 0; i < streams.length; i++) {
88-
itemArray[i] = streams[i].format + " " + streams[i].resolution;
89-
if(defaultResolution.equals(streams[i].resolution)) {
89+
for(int i = 0; i < videoStreams.length; i++) {
90+
itemArray[i] = VideoInfo.getNameById(videoStreams[i].format) + " " + videoStreams[i].resolution;
91+
if(defaultResolution.equals(videoStreams[i].resolution)) {
9092
defaultResolutionPos = i;
9193
}
9294
}
@@ -99,6 +101,27 @@ public void setStreams(VideoInfo.VideoStream[] streams) {
99101
,new ForamatItemSelectListener());
100102
ab.setSelectedNavigationItem(defaultResolutionPos);
101103
}
104+
105+
// set audioStream
106+
audioStream = null;
107+
String preferedFormat = PreferenceManager.getDefaultSharedPreferences(context)
108+
.getString(context.getString(R.string.defaultAudioFormatPreference), "webm");
109+
if(preferedFormat.equals("webm")) {
110+
for(VideoInfo.AudioStream s : audioStreams) {
111+
if(s.format == VideoInfo.I_WEBMA) {
112+
audioStream = s;
113+
}
114+
}
115+
} else if(preferedFormat.equals("m4a")){
116+
for(VideoInfo.AudioStream s : audioStreams) {
117+
Log.d(TAG, VideoInfo.getMimeById(s.format) + " : " + Integer.toString(s.bandWidth));
118+
if(s.format == VideoInfo.I_M4A &&
119+
(audioStream == null || audioStream.bandWidth > s.bandWidth)) {
120+
audioStream = s;
121+
Log.d(TAG, "last choosen");
122+
}
123+
}
124+
}
102125
}
103126

104127
private void selectFormatItem(int i) {
@@ -159,6 +182,9 @@ public boolean onItemSelected(MenuItem item, Context context) {
159182
case R.id.action_play_with_kodi:
160183
playWithKodi();
161184
break;
185+
case R.id.menu_item_play_audio:
186+
playAudio();
187+
break;
162188
default:
163189
Log.e(TAG, "Menu Item not known");
164190
}
@@ -179,7 +205,7 @@ public void playVideo() {
179205
try {
180206
intent.setAction(Intent.ACTION_VIEW);
181207
intent.setDataAndType(Uri.parse(videoStreams[selectedStream].url),
182-
"video/" + videoStreams[selectedStream].format);
208+
VideoInfo.getMimeById(videoStreams[selectedStream].format));
183209
context.startActivity(intent); // HERE !!!
184210
} catch (Exception e) {
185211
e.printStackTrace();
@@ -216,29 +242,17 @@ public void onClick(DialogInterface dialog, int which) {
216242
public void downloadVideo() {
217243
Log.d(TAG, "bla");
218244
if(!videoTitle.isEmpty()) {
219-
String suffix = "";
220-
switch (videoStreams[selectedStream].format) {
221-
case VideoInfo.F_WEBM:
222-
suffix = ".webm";
223-
break;
224-
case VideoInfo.F_MPEG_4:
225-
suffix = ".mp4";
226-
break;
227-
case VideoInfo.F_3GPP:
228-
suffix = ".3gp";
229-
break;
230-
}
231-
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
232-
DownloadManager.Request request = new DownloadManager.Request(
233-
Uri.parse(videoStreams[selectedStream].url));
234-
request.setDestinationUri(Uri.fromFile(new File(
235-
defaultPreferences.getString("download_path_preference", "/storage/emulated/0/NewPipe")
236-
+ "/" + videoTitle + suffix)));
237-
try {
238-
dm.enqueue(request);
239-
} catch (Exception e) {
240-
e.printStackTrace();
241-
}
245+
String videoSuffix = "." + VideoInfo.getSuffixById(videoStreams[selectedStream].format);
246+
String audioSuffix = "." + VideoInfo.getSuffixById(audioStream.format);
247+
Bundle args = new Bundle();
248+
args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix);
249+
args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix);
250+
args.putString(DownloadDialog.TITLE, videoTitle);
251+
args.putString(DownloadDialog.VIDEO_URL, videoStreams[selectedStream].url);
252+
args.putString(DownloadDialog.AUDIO_URL, audioStream.url);
253+
DownloadDialog downloadDialog = new DownloadDialog();
254+
downloadDialog.setArguments(args);
255+
downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
242256
}
243257
}
244258

@@ -282,4 +296,34 @@ public void onClick(DialogInterface dialog, int which) {
282296
}
283297
}
284298
}
299+
300+
public void playAudio() {
301+
Intent intent = new Intent();
302+
try {
303+
intent.setAction(Intent.ACTION_VIEW);
304+
intent.setDataAndType(Uri.parse(audioStream.url),
305+
VideoInfo.getMimeById(audioStream.format));
306+
context.startActivity(intent); // HERE !!!
307+
} catch (Exception e) {
308+
e.printStackTrace();
309+
AlertDialog.Builder builder = new AlertDialog.Builder(context);
310+
builder.setMessage(R.string.noPlayerFound)
311+
.setPositiveButton(R.string.installStreamPlayer, new DialogInterface.OnClickListener() {
312+
@Override
313+
public void onClick(DialogInterface dialog, int which) {
314+
Intent intent = new Intent();
315+
intent.setAction(Intent.ACTION_VIEW);
316+
intent.setData(Uri.parse(context.getString(R.string.fdroidVLCurl)));
317+
context.startActivity(intent);
318+
}
319+
})
320+
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
321+
@Override
322+
public void onClick(DialogInterface dialog, int which) {
323+
Log.i(TAG, "You unlocked a secret unicorn.");
324+
}
325+
});
326+
builder.create().show();
327+
}
328+
}
285329
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.schabi.newpipe;
2+
3+
import android.app.Dialog;
4+
import android.app.DownloadManager;
5+
import android.content.Context;
6+
import android.content.DialogInterface;
7+
import android.content.SharedPreferences;
8+
import android.net.Uri;
9+
import android.os.Bundle;
10+
import android.preference.PreferenceManager;
11+
import android.support.v4.app.DialogFragment;
12+
import android.support.v7.app.AlertDialog;
13+
import android.util.Log;
14+
15+
import java.io.File;
16+
17+
/**
18+
* Created by Christian Schabesberger on 21.09.15.
19+
*
20+
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
21+
* DownloadDialog.java is part of NewPipe.
22+
*
23+
* NewPipe is free software: you can redistribute it and/or modify
24+
* it under the terms of the GNU General Public License as published by
25+
* the Free Software Foundation, either version 3 of the License, or
26+
* (at your option) any later version.
27+
*
28+
* NewPipe is distributed in the hope that it will be useful,
29+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
30+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31+
* GNU General Public License for more details.
32+
*
33+
* You should have received a copy of the GNU General Public License
34+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
35+
*/
36+
37+
public class DownloadDialog extends DialogFragment {
38+
private static final String TAG = DialogFragment.class.getName();
39+
40+
public static final String TITLE = "name";
41+
public static final String FILE_SUFFIX_AUDIO = "file_suffix_audio";
42+
public static final String FILE_SUFFIX_VIDEO = "file_suffix_video";
43+
public static final String AUDIO_URL = "audio_url";
44+
public static final String VIDEO_URL = "video_url";
45+
Bundle arguments;
46+
47+
@Override
48+
public Dialog onCreateDialog(Bundle savedInstanceState) {
49+
arguments = getArguments();
50+
super.onCreateDialog(savedInstanceState);
51+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
52+
builder.setTitle(R.string.downloadDialogTitle)
53+
.setItems(R.array.downloadOptions, new DialogInterface.OnClickListener() {
54+
@Override
55+
public void onClick(DialogInterface dialog, int which) {
56+
Context context = getActivity();
57+
SharedPreferences defaultPreferences = PreferenceManager.getDefaultSharedPreferences(context);
58+
String suffix = "";
59+
String title = arguments.getString(TITLE);
60+
String url = "";
61+
switch(which) {
62+
case 0: // Video
63+
suffix = arguments.getString(FILE_SUFFIX_VIDEO);
64+
url = arguments.getString(VIDEO_URL);
65+
break;
66+
case 1:
67+
suffix = arguments.getString(FILE_SUFFIX_AUDIO);
68+
url = arguments.getString(AUDIO_URL);
69+
break;
70+
default:
71+
Log.d(TAG, "lolz");
72+
}
73+
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
74+
DownloadManager.Request request = new DownloadManager.Request(
75+
Uri.parse(url));
76+
request.setDestinationUri(Uri.fromFile(new File(
77+
defaultPreferences.getString("download_path_preference", "/storage/emulated/0/NewPipe")
78+
+ "/" + title + suffix)));
79+
try {
80+
dm.enqueue(request);
81+
} catch (Exception e) {
82+
e.printStackTrace();
83+
}
84+
}
85+
});
86+
return builder.create();
87+
}
88+
89+
}

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

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,104 @@
2121
*/
2222

2323
import android.graphics.Bitmap;
24+
import android.util.Log;
2425

2526
import java.util.Vector;
2627

2728
public class VideoInfo {
2829

30+
private static final String TAG = VideoInfo.class.toString();
31+
32+
// format identifier
33+
public static final int I_MPEG_4 = 0x0;
34+
public static final int I_3GPP = 0x1;
35+
public static final int I_WEBM = 0x2;
36+
public static final int I_M4A = 0x3;
37+
public static final int I_WEBMA = 0x4;
38+
39+
// format name
2940
public static final String F_MPEG_4 = "MPEG-4";
3041
public static final String F_3GPP = "3GPP";
3142
public static final String F_WEBM = "WebM";
3243
public static final String F_M4A = "m4a";
44+
public static final String F_WEBMA = "WebM";
45+
46+
// file suffix
47+
public static final String C_MPEG_4 = "mp4";
48+
public static final String C_3GPP = "3gp";
49+
public static final String C_WEBM = "webm";
50+
public static final String C_M4A = "m4a";
51+
public static final String C_WEBMA = "webm";
52+
53+
// mimeType
54+
public static final String M_MPEG_4 = "video/mp4";
55+
public static final String M_3GPP = "video/3gpp";
56+
public static final String M_WEBM = "video/webm";
57+
public static final String M_M4A = "audio/mp4";
58+
public static final String M_WEBMA = "audio/webm";
3359

3460
public static final int VIDEO_AVAILABLE = 0x00;
3561
public static final int VIDEO_UNAVAILABLE = 0x01;
3662
public static final int VIDEO_UNAVAILABLE_GEMA = 0x02;
3763

64+
public static String getNameById(int id) {
65+
switch(id) {
66+
case I_MPEG_4: return F_MPEG_4;
67+
case I_3GPP: return F_3GPP;
68+
case I_WEBM: return F_WEBM;
69+
case I_M4A: return F_M4A;
70+
case I_WEBMA: return F_WEBMA;
71+
default: Log.e(TAG, "format not known: " +
72+
Integer.toString(id) + "call the programmer he messed it up.");
73+
}
74+
return "";
75+
}
76+
77+
public static String getSuffixById(int id) {
78+
switch(id) {
79+
case I_MPEG_4: return C_MPEG_4;
80+
case I_3GPP: return C_3GPP;
81+
case I_WEBM: return C_WEBM;
82+
case I_M4A: return C_M4A;
83+
case I_WEBMA: return C_WEBMA;
84+
default: Log.e(TAG, "format not known: " +
85+
Integer.toString(id) + "call the programmer he messed it up.");
86+
}
87+
return "";
88+
}
89+
90+
public static String getMimeById(int id) {
91+
switch(id) {
92+
case I_MPEG_4: return M_MPEG_4;
93+
case I_3GPP: return M_3GPP;
94+
case I_WEBM: return M_WEBM;
95+
case I_M4A: return M_M4A;
96+
case I_WEBMA: return M_WEBMA;
97+
default: Log.e(TAG, "format not known: " +
98+
Integer.toString(id) + "call the programmer he messed it up.");
99+
}
100+
return "";
101+
}
102+
38103
public static class VideoStream {
39-
public VideoStream(String url, String format, String res) {
104+
public VideoStream(String url, int format, String res) {
40105
this.url = url; this.format = format; resolution = res;
41106
}
42107
public String url = ""; //url of the stream
43-
public String format = "";
108+
public int format = -1;
44109
public String resolution = "";
45110
}
46111

47112
public static class AudioStream {
48-
public AudioStream(String url, String format) {
113+
public AudioStream(String url, int format, int bandWidth, int samplingRate) {
49114
this.url = url; this.format = format;
115+
this.bandWidth = bandWidth; this.samplingRate = samplingRate;
50116
}
51117
public String url = "";
52-
public String format = "";
118+
public int format = -1;
119+
public int bandWidth = -1;
120+
public int samplingRate = -1;
121+
53122
}
54123

55124
public String id = "";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void updateInfo(VideoInfo info) {
205205
for (int i = 0; i < streamList.length; i++) {
206206
streamList[i] = streamsToUse.get(i);
207207
}
208-
ActionBarHandler.getHandler().setStreams(streamList);
208+
ActionBarHandler.getHandler().setStreams(streamList, info.audioStreams);
209209
}
210210
break;
211211
case VideoInfo.VIDEO_UNAVAILABLE_GEMA:

0 commit comments

Comments
 (0)