implemented autoplay feature

This commit is contained in:
Christian Schabesberger 2015-09-11 09:50:30 +02:00
parent fde0b2ae7f
commit 8dd05d2974
8 changed files with 32 additions and 6 deletions

View File

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

View File

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

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe;
import android.content.ContentProviderOperation;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
@ -16,7 +17,7 @@ import org.schabi.newpipe.youtube.YoutubeExtractor;
/**
* 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
* 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();
if (savedInstanceState == null) {
// Create the detail fragment and add it to the activity
// using a fragment transaction.
// this means the video was called though another app
if (getIntent().getData() != null) {
videoUrl = getIntent().getData().toString();
StreamingService[] serviceList = ServiceList.getServices();
@ -81,13 +81,18 @@ public class VideoItemDetailActivity extends AppCompatActivity {
}
arguments.putString(VideoItemDetailFragment.VIDEO_URL,
extractor.getVideoUrl(extractor.getVideoId(videoUrl)));
arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY,
PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.autoPlayThroughIntent), false));
} else {
videoUrl = getIntent().getStringExtra(VideoItemDetailFragment.VIDEO_URL);
currentStreamingService = getIntent().getIntExtra(VideoItemDetailFragment.STREAMING_SERVICE, -1);
arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl);
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();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction()

View File

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

View File

@ -25,4 +25,6 @@
<string name="downloadLocation">Download Verzeichnis</string>
<string name="downloadLocationSummary">Verzeichnis in dem heruntergeladene Videos gespeichert werden.</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>

View File

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

View File

@ -25,4 +25,6 @@
<string name="downloadLocation">Download location</string>
<string name="downloadLocationSummary">Path to store downloaded videos in.</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>

View File

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