@Override public void deleteVideo(@NonNull Video video) { catalog.deleteVideo(video, new OfflineCallback<Boolean>() { @Override public void onSuccess(Boolean aBoolean) { } @Override public void onFailure(Throwable throwable) { Log.e(TAG, "Error deleting video: ", throwable); } }); } };
@Override public void rentVideo(@NonNull final Video video) { // Fetch the video object again to avoid using the given video that may have been // changed by previous download. catalog.findVideoByID(video.getId(), new FindVideoListener(video) { @Override public void onVideo(Video newVideo) { MainActivity.this.rentVideo(newVideo); } }); }
@Override public void downloadVideo(@NonNull final Video video) { // bundle has all available captions and audio tracks catalog.getMediaFormatTracksAvailable(video, new MediaDownloadable.MediaFormatListener() { @Override public void onResult(MediaDownloadable mediaDownloadable, Bundle bundle) { BrightcoveDownloadUtil.selectMediaFormatTracksAvailable(mediaDownloadable, bundle); catalog.downloadVideo(video, new OfflineCallback<DownloadStatus>() { @Override public void onSuccess(DownloadStatus downloadStatus) { // Video download started successfully videoListAdapter.notifyVideoChanged(video); } @Override public void onFailure(Throwable throwable) { Log.e(TAG, "Error initializing video download: ", throwable); } }); } }); }
/** * Sets up the view when created. */ private void onCreate() { connectivityMonitor = ConnectivityMonitor.getInstance(this); videoListLabel = ViewUtil.findView(this, R.id.video_list_label); videoListView = ViewUtil.findView(this, R.id.video_list_view); emptyListMessage = ViewUtil.findView(this, R.id.empty_list_message); brightcoveVideoView = ViewUtil.findView(this, R.id.brightcove_video_view); EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter(); catalog = new OfflineCatalog(this, eventEmitter, ACCOUNT_ID, POLICY_KEY); //Configure downloads through the catalog. catalog.setMobileDownloadAllowed(true); catalog.setMeteredDownloadAllowed(false); catalog.setRoamingDownloadAllowed(false); videoListAdapter = new VideoListAdapter(catalog, videoListListener); // Connect the video list view to the adapter RecyclerView videoListView = ViewUtil.findView(this, R.id.video_list_view); videoListView.setAdapter(videoListAdapter); // Setup an adapter to render the playlist items in the spinner view Adapter that // will be used to bind the playlist spinner to the underlying data source. ArrayAdapter<PlaylistModel> playlistAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item/*, playlistNames*/); playlistAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); }
private void handleViewState(final ViewHolder holder, Video video, DownloadStatus status) { if (video.isOfflinePlaybackAllowed()) { holder.estimatedSizeText.setVisibility(View.VISIBLE); catalog.estimateSize(video, new MediaDownloadable.OnVideoSizeCallback() { @Override public void onVideoSizeEstimated(long bytes) { holder.videoStatusText.setVisibility(View.VISIBLE); catalog.getVideoDownloadStatus(holder.video, new OfflineCallback<DownloadStatus>() { @Override public void onSuccess(DownloadStatus downloadStatus) {
@Override public void pauseVideoDownload(@NonNull Video video) { Log.v(TAG,"Calling pauseVideoDownload."); catalog.pauseVideoDownload(video, new OfflineCallback<Integer>() { @Override public void onSuccess(Integer integer) { // Video download was paused successfully } @Override public void onFailure(Throwable throwable) { Log.e(TAG, "Error pausing video download: ", throwable); } }); }
videoListLabel.setVisibility(View.VISIBLE); videoListLabel.setText(R.string.offline_playlist); catalog.findAllVideoDownload( DownloadStatus.STATUS_COMPLETE, new OfflineCallback<List<Video>>() {
@Override protected void onStart() { super.onStart(); ConnectivityMonitor.getInstance(this).addListener(connectivityListener); catalog.addDownloadEventListener(downloadEventListener); updateVideoList(); }
void getVideo(final OfflineCallback<Video> callback) { final Video result = video; if (video.isOfflinePlaybackAllowed()) { catalog.findOfflineVideoById(video.getId(), new OfflineCallback<Video>() { @Override public void onSuccess(Video offlineVideo) { if (offlineVideo != null) { callback.onSuccess(offlineVideo); } else { callback.onSuccess(video); } } @Override public void onFailure(Throwable throwable) { callback.onSuccess(result); } }); } else { callback.onSuccess(result); } } }
@Override public void buyVideo(@NonNull final Video video) { // Fetch the video object again to avoid using the given video that may have been // changed by previous download. catalog.findVideoByID(video.getId(), new FindVideoListener(video) { @Override public void onVideo(Video newVideo) { catalog.requestPurchaseLicense(video, licenseEventListener); } }); }
/** * Called when an offline copy of the video is either cancelled or deleted. * * @param video the video that was removed. */ private void onDownloadRemoved(@NonNull final Video video) { if (connectivityMonitor.isConnected()) { // Fetch the video object again to avoid using the given video that may have been // tainted by previous download. catalog.findVideoByID(video.getId(), new FindVideoListener(video) { @Override public void onVideo(Video newVideo) { videoListAdapter.notifyVideoChanged(newVideo); } }); } else { videoListAdapter.removeVideo(video); onVideoListUpdated(false); } }