From 8dd05d2974bb94c7061d3eabd16c9b05704a29f8 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 11 Sep 2015 09:50:30 +0200 Subject: [PATCH] implemented autoplay feature --- .../java/org/schabi/newpipe/ActionBarHandler.java | 3 ++- .../java/org/schabi/newpipe/PlayVideoActivity.java | 2 ++ .../org/schabi/newpipe/VideoItemDetailActivity.java | 13 +++++++++---- .../org/schabi/newpipe/VideoItemDetailFragment.java | 6 ++++++ app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values/settings_keys.xml | 1 + app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/settings_screen.xml | 9 ++++++++- 8 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java index 4de854105..b3b3eec2e 100644 --- a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java +++ b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java @@ -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); diff --git a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java index dc633b3be..db7d09691 100644 --- a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java +++ b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java @@ -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"; diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java index e3c0fda3e..cc9287796 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java @@ -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 - * 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() diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index a1cb0f33d..842118490 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -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(); diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 7108f61f5..7f020928f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -25,4 +25,6 @@ Download Verzeichnis Verzeichnis in dem heruntergeladene Videos gespeichert werden. Download Verzeichnis eingeben + Automatisch abspielen durch Intent. + Startet ein Video automatisch wenn es von einer anderen App aufgerufen wurde. diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 4f500be34..262becd75 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -2,4 +2,5 @@ download_path_preference use_external_player + autoplay_through_intent \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 977eab300..8679ee1d0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,4 +25,6 @@ Download location Path to store downloaded videos in. Enter download path + Autoplay through Intent + Automatically starts a video when it was called from another app. diff --git a/app/src/main/res/xml/settings_screen.xml b/app/src/main/res/xml/settings_screen.xml index 47d0e2356..d99af4850 100644 --- a/app/src/main/res/xml/settings_screen.xml +++ b/app/src/main/res/xml/settings_screen.xml @@ -5,7 +5,8 @@ + android:title="@string/useExternalPlayerTitle" + android:defaultValue="false"/> + + \ No newline at end of file