remove youtube support
This commit is contained in:
parent
f3f78ea3d1
commit
75edaa27d2
6 changed files with 0 additions and 326 deletions
|
@ -1,50 +0,0 @@
|
||||||
package de.luhmer.owncloudnewsreader;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Fragment;
|
|
||||||
import android.app.FragmentTransaction;
|
|
||||||
|
|
||||||
import com.google.android.youtube.player.YouTubeInitializationResult;
|
|
||||||
import com.google.android.youtube.player.YouTubePlayer;
|
|
||||||
import com.google.android.youtube.player.YouTubePlayerFragment;
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
|
|
||||||
public class YoutubePlayerManager {
|
|
||||||
|
|
||||||
static Fragment.SavedState savedState;
|
|
||||||
static WeakReference<YouTubePlayerFragment> youTubePlayerFragmentRef;
|
|
||||||
|
|
||||||
|
|
||||||
public static void StartYoutubePlayer(final Activity activity, int YOUTUBE_CONTENT_VIEW_ID, final EventBus eventBus, final Runnable onInitSuccess) {
|
|
||||||
YouTubePlayerFragment youTubePlayerFragment = YouTubePlayerFragment.newInstance();
|
|
||||||
if(savedState != null) {
|
|
||||||
youTubePlayerFragment.setInitialSavedState(savedState);
|
|
||||||
}
|
|
||||||
FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
|
|
||||||
ft.add(YOUTUBE_CONTENT_VIEW_ID, youTubePlayerFragment).commit();
|
|
||||||
|
|
||||||
youTubePlayerFragment.initialize("AIzaSyA2OHKWvF_hRVtPmLcwnO8yF6-iah2hjbk", new YouTubePlayer.OnInitializedListener() {
|
|
||||||
@Override
|
|
||||||
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {
|
|
||||||
eventBus.post(new RegisterYoutubeOutput(youTubePlayer, wasRestored));
|
|
||||||
onInitSuccess.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
|
|
||||||
youTubeInitializationResult.getErrorDialog(activity, 0).show();
|
|
||||||
//Toast.makeText(activity, "Error while playing youtube video! (InitializationFailure)", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
youTubePlayerFragmentRef = new WeakReference<>(youTubePlayerFragment);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void safeYoutubeState(Activity activity) {
|
|
||||||
if(youTubePlayerFragmentRef != null && youTubePlayerFragmentRef.get() != null) {
|
|
||||||
savedState = activity.getFragmentManager().saveFragmentInstanceState(youTubePlayerFragmentRef.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,168 +0,0 @@
|
||||||
package de.luhmer.owncloudnewsreader.services.podcast;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.google.android.youtube.player.YouTubePlayer;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import de.luhmer.owncloudnewsreader.model.MediaItem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by david on 31.01.17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class YoutubePlaybackService extends PlaybackService {
|
|
||||||
|
|
||||||
private static final String TAG = YoutubePlaybackService.class.getCanonicalName();
|
|
||||||
YouTubePlayer youTubePlayer;
|
|
||||||
Context context;
|
|
||||||
|
|
||||||
public YoutubePlaybackService(Context context, PodcastStatusListener podcastStatusListener, MediaItem mediaItem) {
|
|
||||||
super(podcastStatusListener, mediaItem);
|
|
||||||
this.context = context;
|
|
||||||
setStatus(Status.PREPARING);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
if(youTubePlayer != null) {
|
|
||||||
youTubePlayer.pause();
|
|
||||||
youTubePlayer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void play() {
|
|
||||||
if(youTubePlayer != null) {
|
|
||||||
youTubePlayer.play();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pause() {
|
|
||||||
if(youTubePlayer != null) {
|
|
||||||
youTubePlayer.pause();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void playbackSpeedChanged(float currentPlaybackSpeed) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void seekTo(double percent) {
|
|
||||||
if(youTubePlayer != null) {
|
|
||||||
double totalDuration = getTotalDuration();
|
|
||||||
int position = (int) ((totalDuration / 100d) * percent);
|
|
||||||
youTubePlayer.seekToMillis(position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public int getCurrentDuration() {
|
|
||||||
if(youTubePlayer != null) {
|
|
||||||
return youTubePlayer.getCurrentTimeMillis();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTotalDuration() {
|
|
||||||
if(youTubePlayer != null) {
|
|
||||||
return youTubePlayer.getDurationMillis();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VideoType getVideoType() {
|
|
||||||
return VideoType.YouTube;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setYoutubePlayer(Object youTubePlayer, boolean wasRestored) {
|
|
||||||
this.youTubePlayer = (YouTubePlayer) youTubePlayer;
|
|
||||||
this.youTubePlayer.setPlaybackEventListener(youtubePlaybackEventListener);
|
|
||||||
this.youTubePlayer.setPlayerStateChangeListener(youtubePlayerStateChangeListener);
|
|
||||||
|
|
||||||
this.youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);
|
|
||||||
|
|
||||||
// Start buffering
|
|
||||||
if (!wasRestored) {
|
|
||||||
Pattern youtubeIdPattern = Pattern.compile(".*?v=([^&]*)");
|
|
||||||
Matcher matcher = youtubeIdPattern.matcher(getMediaItem().link);
|
|
||||||
if(matcher.matches()) {
|
|
||||||
String youtubeId = matcher.group(1);
|
|
||||||
this.youTubePlayer.cueVideo(youtubeId);
|
|
||||||
} else {
|
|
||||||
Toast.makeText(context, "Cannot find youtube video id", Toast.LENGTH_LONG).show();
|
|
||||||
setStatus(Status.FAILED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
YouTubePlayer.PlayerStateChangeListener youtubePlayerStateChangeListener = new YouTubePlayer.PlayerStateChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onLoading() {
|
|
||||||
Log.d(TAG, "onLoading() called");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoaded(String s) {
|
|
||||||
Log.d(TAG, "onLoaded() called with: s = [" + s + "]");
|
|
||||||
youTubePlayer.play();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAdStarted() {
|
|
||||||
Log.d(TAG, "onAdStarted() called");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onVideoStarted() {
|
|
||||||
Log.d(TAG, "onVideoStarted() called");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onVideoEnded() {
|
|
||||||
Log.d(TAG, "onVideoEnded() called");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(YouTubePlayer.ErrorReason errorReason) {
|
|
||||||
Log.d(TAG, "onError() called with: errorReason = [" + errorReason + "]");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
YouTubePlayer.PlaybackEventListener youtubePlaybackEventListener = new YouTubePlayer.PlaybackEventListener() {
|
|
||||||
@Override
|
|
||||||
public void onPlaying() {
|
|
||||||
Log.d(TAG, "onPlaying() called");
|
|
||||||
setStatus(Status.PLAYING);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPaused() {
|
|
||||||
Log.d(TAG, "onPaused() called");
|
|
||||||
setStatus(Status.PAUSED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStopped() {
|
|
||||||
Log.d(TAG, "onStopped() called");
|
|
||||||
setStatus(Status.PAUSED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBuffering(boolean b) {
|
|
||||||
Log.d(TAG, "onBuffering() called with: b = [" + b + "]");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSeekTo(int i) {
|
|
||||||
Log.d(TAG, "onSeekTo() called with: i = [" + i + "]");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -47,7 +47,6 @@ import de.luhmer.owncloudnewsreader.database.model.RssItem;
|
||||||
import de.luhmer.owncloudnewsreader.di.ApiProvider;
|
import de.luhmer.owncloudnewsreader.di.ApiProvider;
|
||||||
import de.luhmer.owncloudnewsreader.events.podcast.PodcastCompletedEvent;
|
import de.luhmer.owncloudnewsreader.events.podcast.PodcastCompletedEvent;
|
||||||
import de.luhmer.owncloudnewsreader.events.podcast.RegisterVideoOutput;
|
import de.luhmer.owncloudnewsreader.events.podcast.RegisterVideoOutput;
|
||||||
import de.luhmer.owncloudnewsreader.events.podcast.RegisterYoutubeOutput;
|
|
||||||
import de.luhmer.owncloudnewsreader.events.podcast.UpdatePodcastStatusEvent;
|
import de.luhmer.owncloudnewsreader.events.podcast.UpdatePodcastStatusEvent;
|
||||||
import de.luhmer.owncloudnewsreader.events.podcast.VideoDoubleClicked;
|
import de.luhmer.owncloudnewsreader.events.podcast.VideoDoubleClicked;
|
||||||
import de.luhmer.owncloudnewsreader.helper.PostDelayHandler;
|
import de.luhmer.owncloudnewsreader.helper.PostDelayHandler;
|
||||||
|
@ -88,10 +87,8 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP
|
||||||
protected ZoomableRelativeLayout rlVideoPodcastSurfaceWrapper;
|
protected ZoomableRelativeLayout rlVideoPodcastSurfaceWrapper;
|
||||||
@BindView(R.id.sliding_layout)
|
@BindView(R.id.sliding_layout)
|
||||||
protected PodcastSlidingUpPanelLayout sliding_layout;
|
protected PodcastSlidingUpPanelLayout sliding_layout;
|
||||||
//YouTubePlayerFragment youtubeplayerfragment;
|
|
||||||
|
|
||||||
private boolean currentlyPlaying = false;
|
private boolean currentlyPlaying = false;
|
||||||
private boolean showedYoutubeFeatureNotAvailableDialog = false;
|
|
||||||
private boolean videoViewInitialized = false;
|
private boolean videoViewInitialized = false;
|
||||||
private boolean isVideoViewVisible = true;
|
private boolean isVideoViewVisible = true;
|
||||||
|
|
||||||
|
@ -210,14 +207,12 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP
|
||||||
Log.d(TAG, "onPause");
|
Log.d(TAG, "onPause");
|
||||||
eventBus.unregister(this);
|
eventBus.unregister(this);
|
||||||
|
|
||||||
YoutubePlayerManager.safeYoutubeState(this);
|
|
||||||
|
|
||||||
//TODO THIS IS NEVER REACHED!
|
//TODO THIS IS NEVER REACHED!
|
||||||
isVideoViewVisible = false;
|
isVideoViewVisible = false;
|
||||||
videoViewInitialized = false;
|
videoViewInitialized = false;
|
||||||
|
|
||||||
eventBus.post(new RegisterVideoOutput(null, null));
|
eventBus.post(new RegisterVideoOutput(null, null));
|
||||||
eventBus.post(new RegisterYoutubeOutput(null, false));
|
|
||||||
|
|
||||||
rlVideoPodcastSurfaceWrapper.setVisibility(View.GONE);
|
rlVideoPodcastSurfaceWrapper.setVisibility(View.GONE);
|
||||||
rlVideoPodcastSurfaceWrapper.removeAllViews();
|
rlVideoPodcastSurfaceWrapper.removeAllViews();
|
||||||
|
@ -392,44 +387,11 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP
|
||||||
togglePodcastVideoViewAnimation();
|
togglePodcastVideoViewAnimation();
|
||||||
}
|
}
|
||||||
} else if(podcast.getVideoType() == PlaybackService.VideoType.YouTube) {
|
} else if(podcast.getVideoType() == PlaybackService.VideoType.YouTube) {
|
||||||
if(BuildConfig.FLAVOR.equals("extra")) {
|
|
||||||
if (!videoViewInitialized) {
|
|
||||||
isVideoViewVisible = true;
|
|
||||||
videoViewInitialized = true;
|
|
||||||
rlVideoPodcastSurfaceWrapper.removeAllViews();
|
|
||||||
|
|
||||||
rlVideoPodcastSurfaceWrapper.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
togglePodcastVideoViewAnimation();
|
|
||||||
|
|
||||||
final int YOUTUBE_CONTENT_VIEW_ID = 10101010;
|
|
||||||
FrameLayout frame = new FrameLayout(this);
|
|
||||||
frame.setId(YOUTUBE_CONTENT_VIEW_ID);
|
|
||||||
rlVideoPodcastSurfaceWrapper.addView(frame);
|
|
||||||
//setContentView(frame, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
|
|
||||||
|
|
||||||
YoutubePlayerManager.StartYoutubePlayer(this, YOUTUBE_CONTENT_VIEW_ID, eventBus, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
togglePodcastVideoViewAnimation();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if(!showedYoutubeFeatureNotAvailableDialog) {
|
|
||||||
showedYoutubeFeatureNotAvailableDialog = true;
|
|
||||||
new AlertDialog.Builder(this)
|
|
||||||
.setTitle(getString(R.string.warning))
|
|
||||||
.setMessage(R.string.dialog_feature_not_available)
|
|
||||||
.setCancelable(true)
|
|
||||||
.setPositiveButton(getString(android.R.string.ok), null)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
isVideoViewVisible = false;
|
isVideoViewVisible = false;
|
||||||
videoViewInitialized = false;
|
videoViewInitialized = false;
|
||||||
|
|
||||||
eventBus.post(new RegisterVideoOutput(null, null));
|
eventBus.post(new RegisterVideoOutput(null, null));
|
||||||
eventBus.post(new RegisterYoutubeOutput(null, false));
|
|
||||||
|
|
||||||
rlVideoPodcastSurfaceWrapper.setVisibility(View.GONE);
|
rlVideoPodcastSurfaceWrapper.setVisibility(View.GONE);
|
||||||
//AlphaAnimator.AnimateVisibilityChange(rlVideoPodcastSurfaceWrapper, View.GONE);
|
//AlphaAnimator.AnimateVisibilityChange(rlVideoPodcastSurfaceWrapper, View.GONE);
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package de.luhmer.owncloudnewsreader.events.podcast;
|
|
||||||
|
|
||||||
public class RegisterYoutubeOutput {
|
|
||||||
|
|
||||||
public RegisterYoutubeOutput(Object youTubePlayer, boolean wasRestored) {
|
|
||||||
this.youTubePlayer = youTubePlayer;
|
|
||||||
this.wasRestored = wasRestored;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object youTubePlayer; // (Type: com.google.android.youtube.player.YouTubePlayer;)
|
|
||||||
public boolean wasRestored;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package de.luhmer.owncloudnewsreader;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
|
||||||
|
|
||||||
public class YoutubePlayerManager {
|
|
||||||
|
|
||||||
public static void StartYoutubePlayer(final Activity activity, int YOUTUBE_CONTENT_VIEW_ID, final EventBus eventBus, final Runnable onInitSuccess) {
|
|
||||||
// Dummy
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
package de.luhmer.owncloudnewsreader.services.podcast;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import de.luhmer.owncloudnewsreader.model.MediaItem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by david on 31.01.17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class YoutubePlaybackService extends PlaybackService {
|
|
||||||
|
|
||||||
public YoutubePlaybackService(Context context, PodcastStatusListener podcastStatusListener, MediaItem mediaItem) {
|
|
||||||
super(podcastStatusListener, mediaItem);
|
|
||||||
setStatus(Status.FAILED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() { }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void play() { }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pause() { }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void playbackSpeedChanged(float currentPlaybackSpeed) { }
|
|
||||||
|
|
||||||
public void seekTo(double percent) { }
|
|
||||||
public int getCurrentDuration() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTotalDuration() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VideoType getVideoType() {
|
|
||||||
return VideoType.YouTube;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setYoutubePlayer(Object youTubePlayer, boolean wasRestored) { }
|
|
||||||
}
|
|
Loading…
Reference in a new issue