Add resolution support up to 4k and 60 fps

- Up to 4k with 60 fps
    - Not every device can play in that resolution and bitrate
    - Add option to hide these high resolution greater than 1080p (2k,4k) for not clutter the menus
- Add a default resolution for the popup, wil be used when opening in popup mode from another app
This commit is contained in:
Mauricio Colli 2017-04-12 03:07:15 -03:00
parent e5bf98a741
commit 3b9a477499
17 changed files with 632 additions and 200 deletions

View file

@ -39,6 +39,7 @@ import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MergingMediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
@ -60,6 +61,7 @@ import com.google.android.exoplayer2.util.Util;
import org.schabi.newpipe.ActivityCommunicator;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.stream_info.AudioStream;
import org.schabi.newpipe.extractor.stream_info.VideoStream;
import java.io.File;
@ -93,6 +95,7 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
public static final String VIDEO_URL = "video_url";
public static final String VIDEO_STREAMS_LIST = "video_streams_list";
public static final String VIDEO_ONLY_AUDIO_STREAM = "video_only_audio_stream";
public static final String VIDEO_TITLE = "video_title";
public static final String INDEX_SEL_VIDEO_STREAM = "index_selected_video_stream";
public static final String START_POSITION = "start_position";
@ -105,7 +108,8 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
private Bitmap videoThumbnail;
private String channelName = "";
private int selectedIndexStream;
private ArrayList<VideoStream> videoStreamsList;
private ArrayList<VideoStream> videoStreamsList = new ArrayList<>();
private AudioStream videoOnlyAudioStream;
/*//////////////////////////////////////////////////////////////////////////
// Player
@ -277,6 +281,9 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
if (serializable instanceof ArrayList) videoStreamsList = (ArrayList<VideoStream>) serializable;
if (serializable instanceof Vector) videoStreamsList = new ArrayList<>((List<VideoStream>) serializable);
Serializable audioStream = intent.getSerializableExtra(VIDEO_ONLY_AUDIO_STREAM);
if (audioStream != null) videoOnlyAudioStream = (AudioStream) audioStream;
videoUrl = intent.getStringExtra(VIDEO_URL);
videoTitle = intent.getStringExtra(VIDEO_TITLE);
videoStartPos = intent.getIntExtra(START_POSITION, -1);
@ -288,13 +295,15 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
e.printStackTrace();
}
playVideo(getSelectedStreamUri(), true);
playVideo(getSelectedVideoStream(), true);
}
public void playVideo(Uri videoURI, boolean autoPlay) {
if (DEBUG) Log.d(TAG, "playVideo() called with: videoURI = [" + videoURI + "], autoPlay = [" + autoPlay + "]");
public void playVideo(VideoStream videoStream, boolean autoPlay) {
if (DEBUG) {
Log.d(TAG, "playVideo() called with: videoStream = [" + videoStream + ", " + videoStream.url + ", isVideoOnly = " + videoStream.isVideoOnly + "], autoPlay = [" + autoPlay + "]");
}
if (videoURI == null || simpleExoPlayer == null) {
if (videoStream == null || videoStream.url == null || simpleExoPlayer == null) {
onError();
return;
}
@ -305,7 +314,7 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
qualityPopupMenu.getMenu().removeGroup(qualityPopupMenuGroupId);
buildQualityMenu(qualityPopupMenu);
videoSource = buildMediaSource(videoURI, MediaFormat.getSuffixById(videoStreamsList.get(selectedIndexStream).format));
videoSource = buildMediaSource(videoStream, MediaFormat.getSuffixById(getSelectedVideoStream().format));
if (simpleExoPlayer.getPlaybackState() != ExoPlayer.STATE_IDLE) simpleExoPlayer.stop();
if (videoStartPos > 0) simpleExoPlayer.seekTo(videoStartPos);
@ -323,22 +332,34 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
if (progressLoop != null) stopProgressLoop();
}
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
if (DEBUG) Log.d(TAG, "buildMediaSource() called with: uri = [" + uri + "], overrideExtension = [" + overrideExtension + "]");
private MediaSource buildMediaSource(VideoStream videoStream, String overrideExtension) {
if (DEBUG) {
Log.d(TAG, "buildMediaSource() called with: videoStream = [" + videoStream + ", " + videoStream.url + "isVideoOnly = " + videoStream.isVideoOnly + "], overrideExtension = [" + overrideExtension + "]");
}
Uri uri = Uri.parse(videoStream.url);
int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri) : Util.inferContentType("." + overrideExtension);
MediaSource mediaSource;
switch (type) {
case C.TYPE_SS:
return new SsMediaSource(uri, cacheDataSourceFactory, new DefaultSsChunkSource.Factory(cacheDataSourceFactory), null, null);
mediaSource = new SsMediaSource(uri, cacheDataSourceFactory, new DefaultSsChunkSource.Factory(cacheDataSourceFactory), null, null);
break;
case C.TYPE_DASH:
return new DashMediaSource(uri, cacheDataSourceFactory, new DefaultDashChunkSource.Factory(cacheDataSourceFactory), null, null);
mediaSource = new DashMediaSource(uri, cacheDataSourceFactory, new DefaultDashChunkSource.Factory(cacheDataSourceFactory), null, null);
break;
case C.TYPE_HLS:
return new HlsMediaSource(uri, cacheDataSourceFactory, null, null);
mediaSource = new HlsMediaSource(uri, cacheDataSourceFactory, null, null);
break;
case C.TYPE_OTHER:
return new ExtractorMediaSource(uri, cacheDataSourceFactory, extractorsFactory, null, null);
mediaSource = new ExtractorMediaSource(uri, cacheDataSourceFactory, extractorsFactory, null, null);
break;
default: {
throw new IllegalStateException("Unsupported type: " + type);
}
}
if (!videoStream.isVideoOnly) return mediaSource;
Uri audioUri = Uri.parse(videoOnlyAudioStream.url);
return new MergingMediaSource(mediaSource, new ExtractorMediaSource(audioUri, cacheDataSourceFactory, extractorsFactory, null, null));
}
public void buildQualityMenu(PopupMenu popupMenu) {
@ -346,7 +367,7 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
VideoStream videoStream = videoStreamsList.get(i);
popupMenu.getMenu().add(qualityPopupMenuGroupId, i, Menu.NONE, MediaFormat.getNameById(videoStream.format) + " " + videoStream.resolution);
}
qualityTextView.setText(videoStreamsList.get(selectedIndexStream).resolution);
qualityTextView.setText(getSelectedVideoStream().resolution);
popupMenu.setOnMenuItemClickListener(this);
popupMenu.setOnDismissListener(this);
@ -590,7 +611,7 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
if (DEBUG) Log.d(TAG, "onVideoPlayPause() called");
if (currentState == STATE_COMPLETED) {
changeState(STATE_LOADING);
if (qualityChanged) playVideo(getSelectedStreamUri(), true);
if (qualityChanged) playVideo(getSelectedVideoStream(), true);
simpleExoPlayer.seekTo(0);
return;
}
@ -632,10 +653,10 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
if (selectedIndexStream == menuItem.getItemId()) return true;
setVideoStartPos((int) getPlayer().getCurrentPosition());
if (!(getCurrentState() == STATE_COMPLETED)) playVideo(Uri.parse(getVideoStreamsList().get(menuItem.getItemId()).url), wasPlaying);
selectedIndexStream = menuItem.getItemId();
if (!(getCurrentState() == STATE_COMPLETED)) playVideo(getSelectedVideoStream(), wasPlaying);
else qualityChanged = true;
selectedIndexStream = menuItem.getItemId();
qualityTextView.setText(menuItem.getTitle());
return true;
}
@ -647,7 +668,7 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
public void onDismiss(PopupMenu menu) {
if (DEBUG) Log.d(TAG, "onDismiss() called with: menu = [" + menu + "]");
isQualityPopupMenuVisible = false;
qualityTextView.setText(videoStreamsList.get(selectedIndexStream).resolution);
qualityTextView.setText(getSelectedVideoStream().resolution);
}
public abstract void onFullScreenButtonClicked();
@ -658,7 +679,7 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
isQualityPopupMenuVisible = true;
animateView(getControlsRoot(), true, 300, 0);
VideoStream videoStream = videoStreamsList.get(selectedIndexStream);
VideoStream videoStream = getSelectedVideoStream();
qualityTextView.setText(MediaFormat.getNameById(videoStream.format) + " " + videoStream.resolution);
wasPlaying = isPlaying();
}
@ -967,8 +988,12 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
return currentState;
}
public VideoStream getSelectedVideoStream() {
return videoStreamsList.get(selectedIndexStream);
}
public Uri getSelectedStreamUri() {
return Uri.parse(videoStreamsList.get(selectedIndexStream).url);
return Uri.parse(getSelectedVideoStream().url);
}
public int getQualityPopupMenuGroupId() {
@ -1015,7 +1040,7 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
this.channelName = channelName;
}
public int getSelectedIndexStream() {
public int getSelectedStreamIndex() {
return selectedIndexStream;
}
@ -1023,6 +1048,14 @@ public abstract class AbstractPlayer implements StateInterface, SeekBar.OnSeekBa
this.selectedIndexStream = selectedIndexStream;
}
public void setAudioStream(AudioStream audioStream) {
this.videoOnlyAudioStream = audioStream;
}
public AudioStream getAudioStream() {
return videoOnlyAudioStream;
}
public ArrayList<VideoStream> getVideoStreamsList() {
return videoStreamsList;
}

View file

@ -8,7 +8,6 @@ import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
@ -24,6 +23,8 @@ import android.widget.TextView;
import android.widget.Toast;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.stream_info.VideoStream;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ThemeHelper;
@ -105,10 +106,9 @@ public class ExoPlayerActivity extends Activity {
super.onResume();
if (DEBUG) Log.d(TAG, "onResume() called");
if (activityPaused) {
//playerImpl.getPlayer().setPlayWhenReady(true);
playerImpl.getPlayPauseButton().setImageResource(R.drawable.ic_play_arrow_white);
playerImpl.initPlayer();
playerImpl.playVideo(playerImpl.getSelectedStreamUri(), false);
playerImpl.playVideo(playerImpl.getSelectedVideoStream(), false);
activityPaused = false;
}
}
@ -238,8 +238,8 @@ public class ExoPlayerActivity extends Activity {
}
@Override
public void playVideo(Uri videoURI, boolean autoPlay) {
super.playVideo(videoURI, autoPlay);
public void playVideo(VideoStream videoStream, boolean autoPlay) {
super.playVideo(videoStream, autoPlay);
playPauseButton.setImageResource(autoPlay ? R.drawable.ic_pause_white : R.drawable.ic_play_arrow_white);
}
@ -254,16 +254,10 @@ public class ExoPlayerActivity extends Activity {
return;
}
Intent i = new Intent(ExoPlayerActivity.this, PopupVideoPlayer.class);
i.putExtra(AbstractPlayer.VIDEO_TITLE, getVideoTitle())
.putExtra(AbstractPlayer.CHANNEL_NAME, getChannelName())
.putExtra(AbstractPlayer.VIDEO_URL, getVideoUrl())
.putExtra(AbstractPlayer.INDEX_SEL_VIDEO_STREAM, getSelectedIndexStream())
.putExtra(AbstractPlayer.VIDEO_STREAMS_LIST, getVideoStreamsList())
.putExtra(AbstractPlayer.START_POSITION, ((int) getPlayer().getCurrentPosition()));
context.startService(i);
if (playerImpl != null) playerImpl.destroy();
context.startService(NavigationHelper.getOpenPlayerIntent(context, PopupVideoPlayer.class, playerImpl));
((View) getControlAnimationView().getParent()).setVisibility(View.GONE);
if (playerImpl.isPlaying()) playerImpl.getPlayer().setPlayWhenReady(false);
ExoPlayerActivity.this.finish();
}
@ -346,7 +340,7 @@ public class ExoPlayerActivity extends Activity {
@Override
public void onDismiss(PopupMenu menu) {
super.onDismiss(menu);
if (isPlaying()) animateView(getControlsRoot(), false, 500, 0, true);
if (isPlaying()) animateView(getControlsRoot(), false, 500, 0);
}
@Override

View file

@ -12,7 +12,6 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
@ -36,18 +35,16 @@ import org.schabi.newpipe.ActivityCommunicator;
import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
import org.schabi.newpipe.ReCaptchaActivity;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.stream_info.StreamExtractor;
import org.schabi.newpipe.extractor.stream_info.StreamInfo;
import org.schabi.newpipe.extractor.stream_info.VideoStream;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.ThemeHelper;
import org.schabi.newpipe.util.Utils;
import java.io.IOException;
import java.util.ArrayList;
import org.schabi.newpipe.workers.StreamExtractorWorker;
/**
* Service Popup Player implementing AbstractPlayer
@ -85,6 +82,7 @@ public class PopupVideoPlayer extends Service {
private DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder().cacheInMemory(true).build();
private AbstractPlayerImpl playerImpl;
private StreamExtractorWorker currentExtractorWorker;
/*//////////////////////////////////////////////////////////////////////////
// Service LifeCycle
@ -110,8 +108,8 @@ public class PopupVideoPlayer extends Service {
if (imageLoader != null) imageLoader.clearMemoryCache();
if (intent.getStringExtra(Constants.KEY_URL) != null) {
playerImpl.setStartedFromNewPipe(false);
Thread fetcher = new Thread(new FetcherRunnable(intent));
fetcher.start();
currentExtractorWorker = new StreamExtractorWorker(this, 0, intent.getStringExtra(Constants.KEY_URL), new FetcherRunnable(this));
currentExtractorWorker.start();
} else {
playerImpl.setStartedFromNewPipe(true);
playerImpl.handleIntent(intent);
@ -135,6 +133,10 @@ public class PopupVideoPlayer extends Service {
if (imageLoader != null) imageLoader.clearMemoryCache();
if (notificationManager != null) notificationManager.cancel(NOTIFICATION_ID);
if (broadcastReceiver != null) unregisterReceiver(broadcastReceiver);
if (currentExtractorWorker != null) {
currentExtractorWorker.cancel();
currentExtractorWorker = null;
}
}
@Override
@ -306,8 +308,8 @@ public class PopupVideoPlayer extends Service {
}
@Override
public void playVideo(Uri videoURI, boolean autoPlay) {
super.playVideo(videoURI, autoPlay);
public void playVideo(VideoStream videoStream, boolean autoPlay) {
super.playVideo(videoStream, autoPlay);
windowLayoutParams.width = (int) getMinimumVideoWidth(currentPopupHeight);
windowManager.updateViewLayout(getRootView(), windowLayoutParams);
@ -321,18 +323,8 @@ public class PopupVideoPlayer extends Service {
public void onFullScreenButtonClicked() {
if (DEBUG) Log.d(TAG, "onFullScreenButtonClicked() called");
Intent intent;
//if (getSharedPreferences().getBoolean(getResources().getString(R.string.use_exoplayer_key), false)) {
// TODO: Remove this check when ExoPlayer is the default
// For now just disable the non-exoplayer player
//noinspection ConstantConditions,ConstantIfStatement
if (true) {
intent = new Intent(PopupVideoPlayer.this, ExoPlayerActivity.class)
.putExtra(AbstractPlayer.VIDEO_TITLE, getVideoTitle())
.putExtra(AbstractPlayer.VIDEO_URL, getVideoUrl())
.putExtra(AbstractPlayer.CHANNEL_NAME, getChannelName())
.putExtra(AbstractPlayer.INDEX_SEL_VIDEO_STREAM, getSelectedIndexStream())
.putExtra(AbstractPlayer.VIDEO_STREAMS_LIST, getVideoStreamsList())
.putExtra(AbstractPlayer.START_POSITION, ((int) getPlayer().getCurrentPosition()));
if (!getSharedPreferences().getBoolean(getResources().getString(R.string.use_old_player_key), false)) {
intent = NavigationHelper.getOpenPlayerIntent(context, ExoPlayerActivity.class, playerImpl);
if (!playerImpl.isStartedFromNewPipe()) intent.putExtra(AbstractPlayer.STARTED_FROM_NEWPIPE, false);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} else {
@ -343,8 +335,9 @@ public class PopupVideoPlayer extends Service {
.putExtra(PlayVideoActivity.START_POSITION, Math.round(getPlayer().getCurrentPosition() / 1000f));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
context.startActivity(intent);
stopSelf();
if (playerImpl != null) playerImpl.destroy();
context.startActivity(intent);
}
@Override
@ -510,84 +503,123 @@ public class PopupVideoPlayer extends Service {
/**
* Fetcher used if open by a link out of NewPipe
*/
private class FetcherRunnable implements Runnable {
private final Intent intent;
private class FetcherRunnable implements StreamExtractorWorker.OnStreamInfoReceivedListener {
private final Context context;
private final Handler mainHandler;
FetcherRunnable(Intent intent) {
this.intent = intent;
FetcherRunnable(Context context) {
this.mainHandler = new Handler(PopupVideoPlayer.this.getMainLooper());
this.context = context;
}
@Override
public void run() {
StreamExtractor streamExtractor;
try {
StreamingService service = NewPipe.getService(0);
if (service == null) return;
streamExtractor = service.getExtractorInstance(intent.getStringExtra(Constants.KEY_URL));
StreamInfo info = StreamInfo.getVideoInfo(streamExtractor);
playerImpl.setVideoStreamsList(info.video_streams instanceof ArrayList
? (ArrayList<VideoStream>) info.video_streams
: new ArrayList<>(info.video_streams));
public void onReceive(StreamInfo info) {
playerImpl.setVideoTitle(info.title);
playerImpl.setVideoUrl(info.webpage_url);
playerImpl.setChannelName(info.uploader);
int defaultResolution = Utils.getPreferredResolution(PopupVideoPlayer.this, info.video_streams);
playerImpl.setSelectedIndexStream(defaultResolution);
playerImpl.setVideoStreamsList(Utils.getSortedStreamVideosList(context, info.video_streams, info.video_only_streams, false));
playerImpl.setAudioStream(Utils.getHighestQualityAudio(info.audio_streams));
if (DEBUG) {
Log.d(TAG, "FetcherRunnable.StreamExtractor: chosen = "
+ MediaFormat.getNameById(info.video_streams.get(defaultResolution).format) + " "
+ info.video_streams.get(defaultResolution).resolution + " > "
+ info.video_streams.get(defaultResolution).url);
}
int defaultResolution = Utils.getPopupDefaultResolution(context, playerImpl.getVideoStreamsList());
playerImpl.setSelectedIndexStream(defaultResolution);
playerImpl.setVideoUrl(info.webpage_url);
playerImpl.setVideoTitle(info.title);
playerImpl.setChannelName(info.uploader);
if (info.start_position > 0) playerImpl.setVideoStartPos(info.start_position * 1000);
else playerImpl.setVideoStartPos(-1);
mainHandler.post(new Runnable() {
@Override
public void run() {
playerImpl.playVideo(playerImpl.getSelectedStreamUri(), true);
}
});
imageLoader.resume();
imageLoader.loadImage(info.thumbnail_url, displayImageOptions, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, final Bitmap loadedImage) {
mainHandler.post(new Runnable() {
@Override
public void run() {
playerImpl.setVideoThumbnail(loadedImage);
if (loadedImage != null) notRemoteView.setImageViewBitmap(R.id.notificationCover, loadedImage);
updateNotification(-1);
ActivityCommunicator.getCommunicator().backgroundPlayerThumbnail = loadedImage;
}
});
}
});
} catch (IOException ie) {
if (DEBUG) ie.printStackTrace();
mainHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(PopupVideoPlayer.this, R.string.network_error, Toast.LENGTH_SHORT).show();
}
});
stopSelf();
} catch (Exception e) {
if (DEBUG) e.printStackTrace();
mainHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(PopupVideoPlayer.this, R.string.content_not_available, Toast.LENGTH_SHORT).show();
}
});
stopSelf();
if (DEBUG) {
Log.d(TAG, "FetcherRunnable.StreamExtractor: chosen = "
+ MediaFormat.getNameById(info.video_streams.get(defaultResolution).format) + " "
+ info.video_streams.get(defaultResolution).resolution + " > "
+ info.video_streams.get(defaultResolution).url);
}
if (info.start_position > 0) playerImpl.setVideoStartPos(info.start_position * 1000);
else playerImpl.setVideoStartPos(-1);
mainHandler.post(new Runnable() {
@Override
public void run() {
playerImpl.playVideo(playerImpl.getSelectedVideoStream(), true);
}
});
imageLoader.resume();
imageLoader.loadImage(info.thumbnail_url, displayImageOptions, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, final Bitmap loadedImage) {
mainHandler.post(new Runnable() {
@Override
public void run() {
playerImpl.setVideoThumbnail(loadedImage);
if (loadedImage != null) notRemoteView.setImageViewBitmap(R.id.notificationCover, loadedImage);
updateNotification(-1);
ActivityCommunicator.getCommunicator().backgroundPlayerThumbnail = loadedImage;
}
});
}
});
}
@Override
public void onError(final int messageId) {
mainHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, messageId, Toast.LENGTH_LONG).show();
}
});
stopSelf();
}
@Override
public void onReCaptchaException() {
mainHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, R.string.recaptcha_request_toast, Toast.LENGTH_LONG).show();
}
});
// Starting ReCaptcha Challenge Activity
Intent intent = new Intent(context, ReCaptchaActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
stopSelf();
}
@Override
public void onBlockedByGemaError() {
mainHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, R.string.blocked_by_gema, Toast.LENGTH_LONG).show();
}
});
stopSelf();
}
@Override
public void onContentErrorWithMessage(final int messageId) {
mainHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, messageId, Toast.LENGTH_LONG).show();
}
});
stopSelf();
}
@Override
public void onContentError() {
mainHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, R.string.content_not_available, Toast.LENGTH_LONG).show();
}
});
stopSelf();
}
@Override
public void onUnrecoverableError(Exception exception) {
stopSelf();
}
}