Skip to content

Commit 8dd05d2

Browse files
author
Christian Schabesberger
committed
implemented autoplay feature
1 parent fde0b2a commit 8dd05d2

8 files changed

Lines changed: 32 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public void setupNavMenu(AppCompatActivity activity) {
7070
}
7171

7272
public void setStreams(VideoInfo.Stream[] streams) {
73+
// // TODO: 11.09.15 add auto stream option
7374
this.streams = streams;
7475
selectedStream = 0;
7576
String[] itemArray = new String[streams.length];
@@ -89,7 +90,7 @@ private void selectFormatItem(int i) {
8990
selectedStream = i;
9091
}
9192

92-
public boolean setupMenu(Menu menu, MenuInflater inflater, Context constext) {
93+
public boolean setupMenu(Menu menu, MenuInflater inflater, Context context) {
9394
this.context = context;
9495
// CAUTION set item properties programmatically otherwise it would not be accepted by
9596
// appcompat itemsinflater.inflate(R.menu.videoitem_detail, menu);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
public class PlayVideoActivity extends AppCompatActivity {
4343

44+
//// TODO: 11.09.15 add "choose stream" menu
45+
4446
private static final String TAG = PlayVideoActivity.class.toString();
4547
public static final String VIDEO_URL = "video_url";
4648
public static final String STREAM_URL = "stream_url";

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.schabi.newpipe;
22

33
import android.content.ContentProviderOperation;
4+
import android.preference.PreferenceManager;
45
import android.support.v7.app.ActionBar;
56
import android.support.v7.app.AppCompatActivity;
67
import android.content.Intent;
@@ -16,7 +17,7 @@
1617

1718
/**
1819
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
19-
* ActionBarHandler.java is part of NewPipe.
20+
* VideoItemDetailActivity.java is part of NewPipe.
2021
*
2122
* NewPipe is free software: you can redistribute it and/or modify
2223
* it under the terms of the GNU General Public License as published by
@@ -60,8 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
6061

6162
Bundle arguments = new Bundle();
6263
if (savedInstanceState == null) {
63-
// Create the detail fragment and add it to the activity
64-
// using a fragment transaction.
64+
// this means the video was called though another app
6565
if (getIntent().getData() != null) {
6666
videoUrl = getIntent().getData().toString();
6767
StreamingService[] serviceList = ServiceList.getServices();
@@ -81,13 +81,18 @@ protected void onCreate(Bundle savedInstanceState) {
8181
}
8282
arguments.putString(VideoItemDetailFragment.VIDEO_URL,
8383
extractor.getVideoUrl(extractor.getVideoId(videoUrl)));
84-
84+
arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY,
85+
PreferenceManager.getDefaultSharedPreferences(this)
86+
.getBoolean(getString(R.string.autoPlayThroughIntent), false));
8587
} else {
8688
videoUrl = getIntent().getStringExtra(VideoItemDetailFragment.VIDEO_URL);
8789
currentStreamingService = getIntent().getIntExtra(VideoItemDetailFragment.STREAMING_SERVICE, -1);
8890
arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl);
8991
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingService);
92+
arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false);
9093
}
94+
// Create the detail fragment and add it to the activity
95+
// using a fragment transaction.
9196
VideoItemDetailFragment fragment = new VideoItemDetailFragment();
9297
fragment.setArguments(arguments);
9398
getSupportFragmentManager().beginTransaction()

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public class VideoItemDetailFragment extends Fragment {
5252
public static final String ARG_ITEM_ID = "item_id";
5353
public static final String VIDEO_URL = "video_url";
5454
public static final String STREAMING_SERVICE = "streaming_service";
55+
public static final String AUTO_PLAY = "auto_play";
5556

57+
private boolean autoPlayEnabled = false;
5658
private Thread extractorThread = null;
5759

5860
private class ExtractorRunnable implements Runnable {
@@ -206,6 +208,9 @@ public void updateInfo(VideoInfo info) {
206208
Log.e(TAG, "Video Availeble Status not known.");
207209
}
208210

211+
if(autoPlayEnabled) {
212+
ActionBarHandler.getHandler().playVideo();
213+
}
209214
} catch (java.lang.NullPointerException e) {
210215
Log.w(TAG, "updateInfo(): Fragment closed before thread ended work... or else");
211216
e.printStackTrace();
@@ -236,6 +241,7 @@ public void onCreate(Bundle savedInstanceState) {
236241
getArguments().getInt(STREAMING_SERVICE));
237242
extractorThread = new Thread(new ExtractorRunnable(
238243
getArguments().getString(VIDEO_URL), streamingService.getExtractorClass(), this));
244+
autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY);
239245
extractorThread.start();
240246
} catch (Exception e) {
241247
e.printStackTrace();

app/src/main/res/values-de/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@
2525
<string name="downloadLocation">Download Verzeichnis</string>
2626
<string name="downloadLocationSummary">Verzeichnis in dem heruntergeladene Videos gespeichert werden.</string>
2727
<string name="downloadLocationDialogTitle">Download Verzeichnis eingeben</string>
28+
<string name="autoPlayThroughIntentTitle">Automatisch abspielen durch Intent.</string>
29+
<string name="autoPlayThroughIntentSummary">Startet ein Video automatisch wenn es von einer anderen App aufgerufen wurde.</string>
2830
</resources>

app/src/main/res/values/settings_keys.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<resources>
33
<string name="downloadPathPreference">download_path_preference</string>
44
<string name="useExternalPlayer">use_external_player</string>
5+
<string name="autoPlayThroughIntent">autoplay_through_intent</string>
56
</resources>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@
2525
<string name="downloadLocation">Download location</string>
2626
<string name="downloadLocationSummary">Path to store downloaded videos in.</string>
2727
<string name="downloadLocationDialogTitle">Enter download path</string>
28+
<string name="autoPlayThroughIntentTitle">Autoplay through Intent</string>
29+
<string name="autoPlayThroughIntentSummary">Automatically starts a video when it was called from another app.</string>
2830
</resources>

app/src/main/res/xml/settings_screen.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
<CheckBoxPreference
77
android:key="@string/useExternalPlayer"
8-
android:title="@string/useExternalPlayerTitle"/>
8+
android:title="@string/useExternalPlayerTitle"
9+
android:defaultValue="false"/>
910

1011
<EditTextPreference
1112
android:key="@string/downloadPathPreference"
@@ -14,4 +15,10 @@
1415
android:dialogTitle="@string/downloadLocationDialogTitle"
1516
android:defaultValue=""/>
1617

18+
<CheckBoxPreference
19+
android:key="@string/autoPlayThroughIntent"
20+
android:title="@string/autoPlayThroughIntentTitle"
21+
android:summary="@string/autoPlayThroughIntentSummary"
22+
android:defaultValue="false" />
23+
1724
</PreferenceScreen>

0 commit comments

Comments
 (0)