implemented autoplay feature

pull/12/head
Christian Schabesberger 2015-09-11 09:50:30 +02:00
rodzic fde0b2ae7f
commit 8dd05d2974
8 zmienionych plików z 32 dodań i 6 usunięć

Wyświetl plik

@ -70,6 +70,7 @@ public class ActionBarHandler {
} }
public void setStreams(VideoInfo.Stream[] streams) { public void setStreams(VideoInfo.Stream[] streams) {
// // TODO: 11.09.15 add auto stream option
this.streams = streams; this.streams = streams;
selectedStream = 0; selectedStream = 0;
String[] itemArray = new String[streams.length]; String[] itemArray = new String[streams.length];
@ -89,7 +90,7 @@ public class ActionBarHandler {
selectedStream = i; selectedStream = i;
} }
public boolean setupMenu(Menu menu, MenuInflater inflater, Context constext) { public boolean setupMenu(Menu menu, MenuInflater inflater, Context context) {
this.context = context; this.context = context;
// CAUTION set item properties programmatically otherwise it would not be accepted by // CAUTION set item properties programmatically otherwise it would not be accepted by
// appcompat itemsinflater.inflate(R.menu.videoitem_detail, menu); // appcompat itemsinflater.inflate(R.menu.videoitem_detail, menu);

Wyświetl plik

@ -41,6 +41,8 @@ import android.widget.VideoView;
public class PlayVideoActivity extends AppCompatActivity { public class PlayVideoActivity extends AppCompatActivity {
//// TODO: 11.09.15 add "choose stream" menu
private static final String TAG = PlayVideoActivity.class.toString(); private static final String TAG = PlayVideoActivity.class.toString();
public static final String VIDEO_URL = "video_url"; public static final String VIDEO_URL = "video_url";
public static final String STREAM_URL = "stream_url"; public static final String STREAM_URL = "stream_url";

Wyświetl plik

@ -1,6 +1,7 @@
package org.schabi.newpipe; package org.schabi.newpipe;
import android.content.ContentProviderOperation; import android.content.ContentProviderOperation;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.content.Intent; import android.content.Intent;
@ -16,7 +17,7 @@ import org.schabi.newpipe.youtube.YoutubeExtractor;
/** /**
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
* ActionBarHandler.java is part of NewPipe. * VideoItemDetailActivity.java is part of NewPipe.
* *
* NewPipe is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -60,8 +61,7 @@ public class VideoItemDetailActivity extends AppCompatActivity {
Bundle arguments = new Bundle(); Bundle arguments = new Bundle();
if (savedInstanceState == null) { if (savedInstanceState == null) {
// Create the detail fragment and add it to the activity // this means the video was called though another app
// using a fragment transaction.
if (getIntent().getData() != null) { if (getIntent().getData() != null) {
videoUrl = getIntent().getData().toString(); videoUrl = getIntent().getData().toString();
StreamingService[] serviceList = ServiceList.getServices(); StreamingService[] serviceList = ServiceList.getServices();
@ -81,13 +81,18 @@ public class VideoItemDetailActivity extends AppCompatActivity {
} }
arguments.putString(VideoItemDetailFragment.VIDEO_URL, arguments.putString(VideoItemDetailFragment.VIDEO_URL,
extractor.getVideoUrl(extractor.getVideoId(videoUrl))); extractor.getVideoUrl(extractor.getVideoId(videoUrl)));
arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY,
PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.autoPlayThroughIntent), false));
} else { } else {
videoUrl = getIntent().getStringExtra(VideoItemDetailFragment.VIDEO_URL); videoUrl = getIntent().getStringExtra(VideoItemDetailFragment.VIDEO_URL);
currentStreamingService = getIntent().getIntExtra(VideoItemDetailFragment.STREAMING_SERVICE, -1); currentStreamingService = getIntent().getIntExtra(VideoItemDetailFragment.STREAMING_SERVICE, -1);
arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl); arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl);
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingService); arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingService);
arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false);
} }
// Create the detail fragment and add it to the activity
// using a fragment transaction.
VideoItemDetailFragment fragment = new VideoItemDetailFragment(); VideoItemDetailFragment fragment = new VideoItemDetailFragment();
fragment.setArguments(arguments); fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()

Wyświetl plik

@ -52,7 +52,9 @@ public class VideoItemDetailFragment extends Fragment {
public static final String ARG_ITEM_ID = "item_id"; public static final String ARG_ITEM_ID = "item_id";
public static final String VIDEO_URL = "video_url"; public static final String VIDEO_URL = "video_url";
public static final String STREAMING_SERVICE = "streaming_service"; public static final String STREAMING_SERVICE = "streaming_service";
public static final String AUTO_PLAY = "auto_play";
private boolean autoPlayEnabled = false;
private Thread extractorThread = null; private Thread extractorThread = null;
private class ExtractorRunnable implements Runnable { private class ExtractorRunnable implements Runnable {
@ -206,6 +208,9 @@ public class VideoItemDetailFragment extends Fragment {
Log.e(TAG, "Video Availeble Status not known."); Log.e(TAG, "Video Availeble Status not known.");
} }
if(autoPlayEnabled) {
ActionBarHandler.getHandler().playVideo();
}
} catch (java.lang.NullPointerException e) { } catch (java.lang.NullPointerException e) {
Log.w(TAG, "updateInfo(): Fragment closed before thread ended work... or else"); Log.w(TAG, "updateInfo(): Fragment closed before thread ended work... or else");
e.printStackTrace(); e.printStackTrace();
@ -236,6 +241,7 @@ public class VideoItemDetailFragment extends Fragment {
getArguments().getInt(STREAMING_SERVICE)); getArguments().getInt(STREAMING_SERVICE));
extractorThread = new Thread(new ExtractorRunnable( extractorThread = new Thread(new ExtractorRunnable(
getArguments().getString(VIDEO_URL), streamingService.getExtractorClass(), this)); getArguments().getString(VIDEO_URL), streamingService.getExtractorClass(), this));
autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY);
extractorThread.start(); extractorThread.start();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

Wyświetl plik

@ -25,4 +25,6 @@
<string name="downloadLocation">Download Verzeichnis</string> <string name="downloadLocation">Download Verzeichnis</string>
<string name="downloadLocationSummary">Verzeichnis in dem heruntergeladene Videos gespeichert werden.</string> <string name="downloadLocationSummary">Verzeichnis in dem heruntergeladene Videos gespeichert werden.</string>
<string name="downloadLocationDialogTitle">Download Verzeichnis eingeben</string> <string name="downloadLocationDialogTitle">Download Verzeichnis eingeben</string>
<string name="autoPlayThroughIntentTitle">Automatisch abspielen durch Intent.</string>
<string name="autoPlayThroughIntentSummary">Startet ein Video automatisch wenn es von einer anderen App aufgerufen wurde.</string>
</resources> </resources>

Wyświetl plik

@ -2,4 +2,5 @@
<resources> <resources>
<string name="downloadPathPreference">download_path_preference</string> <string name="downloadPathPreference">download_path_preference</string>
<string name="useExternalPlayer">use_external_player</string> <string name="useExternalPlayer">use_external_player</string>
<string name="autoPlayThroughIntent">autoplay_through_intent</string>
</resources> </resources>

Wyświetl plik

@ -25,4 +25,6 @@
<string name="downloadLocation">Download location</string> <string name="downloadLocation">Download location</string>
<string name="downloadLocationSummary">Path to store downloaded videos in.</string> <string name="downloadLocationSummary">Path to store downloaded videos in.</string>
<string name="downloadLocationDialogTitle">Enter download path</string> <string name="downloadLocationDialogTitle">Enter download path</string>
<string name="autoPlayThroughIntentTitle">Autoplay through Intent</string>
<string name="autoPlayThroughIntentSummary">Automatically starts a video when it was called from another app.</string>
</resources> </resources>

Wyświetl plik

@ -5,7 +5,8 @@
<CheckBoxPreference <CheckBoxPreference
android:key="@string/useExternalPlayer" android:key="@string/useExternalPlayer"
android:title="@string/useExternalPlayerTitle"/> android:title="@string/useExternalPlayerTitle"
android:defaultValue="false"/>
<EditTextPreference <EditTextPreference
android:key="@string/downloadPathPreference" android:key="@string/downloadPathPreference"
@ -14,4 +15,10 @@
android:dialogTitle="@string/downloadLocationDialogTitle" android:dialogTitle="@string/downloadLocationDialogTitle"
android:defaultValue=""/> android:defaultValue=""/>
<CheckBoxPreference
android:key="@string/autoPlayThroughIntent"
android:title="@string/autoPlayThroughIntentTitle"
android:summary="@string/autoPlayThroughIntentSummary"
android:defaultValue="false" />
</PreferenceScreen> </PreferenceScreen>