Merge remote-tracking branch 'remotes/upstream/master' into beta
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / preview / PreviewMediaFragment.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20 package com.owncloud.android.ui.preview;
21
22 import android.accounts.Account;
23 import android.accounts.AuthenticatorException;
24 import android.accounts.OperationCanceledException;
25 import android.app.Activity;
26 import android.content.ActivityNotFoundException;
27 import android.graphics.Bitmap;
28 import android.graphics.BitmapFactory;
29 import android.media.MediaMetadataRetriever;
30 import android.net.Uri;
31 import android.os.AsyncTask;
32 import android.support.v7.app.AlertDialog;
33 import android.content.ComponentName;
34 import android.content.Context;
35 import android.content.DialogInterface;
36 import android.content.Intent;
37 import android.content.ServiceConnection;
38 import android.content.res.Configuration;
39 import android.content.res.Resources;
40 import android.media.MediaPlayer;
41 import android.media.MediaPlayer.OnCompletionListener;
42 import android.media.MediaPlayer.OnErrorListener;
43 import android.media.MediaPlayer.OnPreparedListener;
44 import android.os.Bundle;
45 import android.os.IBinder;
46 import android.view.LayoutInflater;
47 import android.view.Menu;
48 import android.view.MenuInflater;
49 import android.view.MenuItem;
50 import android.view.MotionEvent;
51 import android.view.View;
52 import android.view.View.OnTouchListener;
53 import android.view.ViewGroup;
54 import android.widget.ImageView;
55 import android.widget.Toast;
56 import android.widget.VideoView;
57
58 import com.owncloud.android.MainApp;
59 import com.owncloud.android.R;
60 import com.owncloud.android.datamodel.OCFile;
61 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
62 import com.owncloud.android.files.FileMenuFilter;
63 import com.owncloud.android.lib.common.OwnCloudAccount;
64 import com.owncloud.android.lib.common.OwnCloudClient;
65 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
66 import com.owncloud.android.lib.common.OwnCloudCredentials;
67 import com.owncloud.android.lib.common.accounts.AccountUtils;
68 import com.owncloud.android.lib.common.utils.Log_OC;
69 import com.owncloud.android.media.MediaControlView;
70 import com.owncloud.android.media.MediaService;
71 import com.owncloud.android.media.MediaServiceBinder;
72 import com.owncloud.android.ui.activity.FileActivity;
73 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
74 import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
75 import com.owncloud.android.ui.fragment.FileFragment;
76
77 import java.io.IOException;
78 import java.util.concurrent.ExecutionException;
79
80
81 /**
82 * This fragment shows a preview of a downloaded media file (audio or video).
83 *
84 * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will
85 * produce an {@link IllegalStateException}.
86 *
87 * By now, if the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is
88 * generated on instantiation too.
89 */
90 public class PreviewMediaFragment extends FileFragment implements
91 OnTouchListener {
92
93 public static final String EXTRA_FILE = "FILE";
94 public static final String EXTRA_ACCOUNT = "ACCOUNT";
95 private static final String EXTRA_PLAY_POSITION = "PLAY_POSITION";
96 private static final String EXTRA_PLAYING = "PLAYING";
97
98 private View mView;
99 private Account mAccount;
100 private ImageView mImagePreview;
101 private VideoView mVideoPreview;
102 private int mSavedPlaybackPosition;
103 private String mUri;
104
105 private MediaServiceBinder mMediaServiceBinder = null;
106 private MediaControlView mMediaController = null;
107 private MediaServiceConnection mMediaServiceConnection = null;
108 private VideoHelper mVideoHelper;
109 private boolean mAutoplay;
110 public boolean mPrepared;
111
112 private static final String TAG = PreviewMediaFragment.class.getSimpleName();
113
114
115 /**
116 * Creates a fragment to preview a file.
117 * <p/>
118 * When 'fileToDetail' or 'ocAccount' are null
119 *
120 * @param fileToDetail An {@link OCFile} to preview in the fragment
121 * @param ocAccount An ownCloud account; needed to start downloads
122 */
123 public PreviewMediaFragment(
124 OCFile fileToDetail,
125 Account ocAccount,
126 int startPlaybackPosition,
127 boolean autoplay) {
128
129 super(fileToDetail);
130 mAccount = ocAccount;
131 mSavedPlaybackPosition = startPlaybackPosition;
132 mAutoplay = autoplay;
133 }
134
135
136 /**
137 * Creates an empty fragment for previews.
138 * <p/>
139 * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically
140 * (for instance, when the device is turned a aside).
141 * <p/>
142 * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful
143 * construction
144 */
145 public PreviewMediaFragment() {
146 super();
147 mAccount = null;
148 mSavedPlaybackPosition = 0;
149 mAutoplay = true;
150 }
151
152
153 /**
154 * {@inheritDoc}
155 */
156 @Override
157 public void onCreate(Bundle savedInstanceState) {
158 super.onCreate(savedInstanceState);
159 setHasOptionsMenu(true);
160 }
161
162
163 /**
164 * {@inheritDoc}
165 */
166 @Override
167 public View onCreateView(LayoutInflater inflater, ViewGroup container,
168 Bundle savedInstanceState) {
169 super.onCreateView(inflater, container, savedInstanceState);
170 Log_OC.v(TAG, "onCreateView");
171
172
173 mView = inflater.inflate(R.layout.file_preview, container, false);
174
175 mImagePreview = (ImageView) mView.findViewById(R.id.image_preview);
176 mVideoPreview = (VideoView) mView.findViewById(R.id.video_preview);
177 mVideoPreview.setOnTouchListener(this);
178
179 mMediaController = (MediaControlView) mView.findViewById(R.id.media_controller);
180
181 return mView;
182 }
183
184
185 /**
186 * {@inheritDoc}
187 */
188 @Override
189 public void onActivityCreated(Bundle savedInstanceState) {
190 super.onActivityCreated(savedInstanceState);
191 Log_OC.v(TAG, "onActivityCreated");
192
193 OCFile file = getFile();
194 if (savedInstanceState == null) {
195 if (file == null) {
196 throw new IllegalStateException("Instanced with a NULL OCFile");
197 }
198 if (mAccount == null) {
199 throw new IllegalStateException("Instanced with a NULL ownCloud Account");
200 }
201 }
202 else {
203 file = (OCFile) savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE);
204 setFile(file);
205 mAccount = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_ACCOUNT);
206 mSavedPlaybackPosition =
207 savedInstanceState.getInt(PreviewMediaFragment.EXTRA_PLAY_POSITION);
208 mAutoplay = savedInstanceState.getBoolean(PreviewMediaFragment.EXTRA_PLAYING);
209
210 }
211 if (file != null) {
212 if (file.isVideo()) {
213 mVideoPreview.setVisibility(View.VISIBLE);
214 mImagePreview.setVisibility(View.GONE);
215 prepareVideo();
216
217 }
218 else {
219 mVideoPreview.setVisibility(View.GONE);
220 mImagePreview.setVisibility(View.VISIBLE);
221 extractAndSetCoverArt(file);
222 }
223 }
224
225 }
226
227 /**
228 * tries to read the cover art from the audio file and sets it as cover art.
229 *
230 * @param file audio file with potential cover art
231 */
232 private void extractAndSetCoverArt(OCFile file) {
233 if (file.isAudio()) {
234 try {
235 MediaMetadataRetriever mmr = new MediaMetadataRetriever();
236 mmr.setDataSource(file.getStoragePath());
237 byte[] data = mmr.getEmbeddedPicture();
238 if (data != null) {
239 Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
240 mImagePreview.setImageBitmap(bitmap); //associated cover art in bitmap
241 } else {
242 mImagePreview.setImageResource(R.drawable.logo);
243 }
244 } catch (Throwable t) {
245 mImagePreview.setImageResource(R.drawable.logo);
246 }
247 }
248 }
249
250
251 /**
252 * {@inheritDoc}
253 */
254 @Override
255 public void onSaveInstanceState(Bundle outState) {
256 super.onSaveInstanceState(outState);
257 Log_OC.v(TAG, "onSaveInstanceState");
258
259 outState.putParcelable(PreviewMediaFragment.EXTRA_FILE, getFile());
260 outState.putParcelable(PreviewMediaFragment.EXTRA_ACCOUNT, mAccount);
261
262 if (getFile().isVideo()) {
263 mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
264 mAutoplay = mVideoPreview.isPlaying();
265 outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION, mSavedPlaybackPosition);
266 outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING, mAutoplay);
267 }
268 else {
269 outState.putInt(
270 PreviewMediaFragment.EXTRA_PLAY_POSITION,
271 mMediaServiceBinder.getCurrentPosition());
272 outState.putBoolean(
273 PreviewMediaFragment.EXTRA_PLAYING, mMediaServiceBinder.isPlaying());
274 }
275 }
276
277
278 @Override
279 public void onStart() {
280 super.onStart();
281 Log_OC.v(TAG, "onStart");
282
283 OCFile file = getFile();
284 if (file != null) {
285 if (file.isAudio()) {
286 bindMediaService();
287
288 }
289 else {
290 if (file.isVideo()) {
291 stopAudio();
292 playVideo();
293 }
294 }
295 }
296 }
297
298
299 private void stopAudio() {
300 Intent i = new Intent(getActivity(), MediaService.class);
301 i.setAction(MediaService.ACTION_STOP_ALL);
302 getActivity().startService(i);
303 }
304
305
306 /**
307 * {@inheritDoc}
308 */
309 @Override
310 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
311 super.onCreateOptionsMenu(menu, inflater);
312 inflater.inflate(R.menu.file_actions_menu, menu);
313 }
314
315
316 /**
317 * {@inheritDoc}
318 */
319 @Override
320 public void onPrepareOptionsMenu(Menu menu) {
321 super.onPrepareOptionsMenu(menu);
322
323 if (mContainerActivity.getStorageManager() != null) {
324 FileMenuFilter mf = new FileMenuFilter(
325 getFile(),
326 mContainerActivity.getStorageManager().getAccount(),
327 mContainerActivity,
328 getActivity()
329 );
330 mf.filter(menu);
331 }
332
333 // additional restriction for this fragment
334 // TODO allow renaming in PreviewImageFragment
335 MenuItem item = menu.findItem(R.id.action_rename_file);
336 if (item != null) {
337 item.setVisible(false);
338 item.setEnabled(false);
339 }
340
341 // additional restriction for this fragment
342 item = menu.findItem(R.id.action_move);
343 if (item != null) {
344 item.setVisible(false);
345 item.setEnabled(false);
346 }
347
348 // additional restriction for this fragment
349 item = menu.findItem(R.id.action_copy);
350 if (item != null) {
351 item.setVisible(false);
352 item.setEnabled(false);
353 }
354 }
355
356
357 /**
358 * {@inheritDoc}
359 */
360 @Override
361 public boolean onOptionsItemSelected(MenuItem item) {
362 switch (item.getItemId()) {
363 case R.id.action_share_file: {
364 seeShareFile();
365 return true;
366 }
367 case R.id.action_open_file_with: {
368 openFile();
369 return true;
370 }
371 case R.id.action_remove_file: {
372 RemoveFileDialogFragment dialog = RemoveFileDialogFragment.newInstance(getFile());
373 dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION);
374 return true;
375 }
376 case R.id.action_see_details: {
377 seeDetails();
378 return true;
379 }
380 case R.id.action_send_file: {
381 sendFile();
382 return true;
383 }
384 case R.id.action_sync_file: {
385 mContainerActivity.getFileOperationsHelper().syncFile(getFile());
386 return true;
387 }
388 case R.id.action_favorite_file:{
389 mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), true);
390 return true;
391 }
392 case R.id.action_unfavorite_file:{
393 mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), false);
394 return true;
395 }
396 default:
397 return false;
398 }
399 }
400
401
402 /**
403 * Update the file of the fragment with file value
404 *
405 * @param file Replaces the held file with a new one
406 */
407 public void updateFile(OCFile file) {
408 setFile(file);
409 }
410
411 private void sendFile() {
412 stopPreview(false);
413 mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());
414
415 }
416
417 private void seeDetails() {
418 stopPreview(false);
419 mContainerActivity.showDetails(getFile());
420 }
421
422 private void seeShareFile() {
423 stopPreview(false);
424 mContainerActivity.getFileOperationsHelper().showShareFile(getFile());
425 }
426
427 private void prepareVideo() {
428 // create helper to get more control on the playback
429 mVideoHelper = new VideoHelper();
430 mVideoPreview.setOnPreparedListener(mVideoHelper);
431 mVideoPreview.setOnCompletionListener(mVideoHelper);
432 mVideoPreview.setOnErrorListener(mVideoHelper);
433 }
434
435 @SuppressWarnings("static-access")
436 private void playVideo() {
437 // create and prepare control panel for the user
438 mMediaController.setMediaPlayer(mVideoPreview);
439
440 // load the video file in the video player ;
441 // when done, VideoHelper#onPrepared() will be called
442 if (getFile().isDown()) {
443 mUri = getFile().getStoragePath();
444 } else {
445 Context context = MainApp.getAppContext();
446 Account account = mContainerActivity.getStorageManager().getAccount();
447
448 mUri = generateUrlWithCredentials(account, context, getFile());
449 }
450
451 mVideoPreview.setVideoURI(getFile().getStorageUri());
452 }
453
454 public static String generateUrlWithCredentials(Account account, Context context, OCFile file){
455 OwnCloudAccount ocAccount = null;
456 try {
457 ocAccount = new OwnCloudAccount(account, context);
458
459 final ClientGenerationTask task = new ClientGenerationTask();
460 task.execute(ocAccount);
461
462 OwnCloudClient mClient = task.get();
463 String url = AccountUtils.constructFullURLForAccount(context, account) + Uri.encode(file.getRemotePath(), "/");
464 OwnCloudCredentials credentials = mClient.getCredentials();
465
466 return url.replace("//", "//" + credentials.getUsername() + ":" + credentials.getAuthToken() + "@");
467
468 } catch (AccountUtils.AccountNotFoundException e) {
469 e.printStackTrace();
470
471 } catch (InterruptedException e) {
472 e.printStackTrace();
473 } catch (ExecutionException e) {
474 e.printStackTrace();
475 }
476 return "";
477 }
478
479 public static class ClientGenerationTask extends AsyncTask<Object, Void, OwnCloudClient> {
480 @Override
481 protected OwnCloudClient doInBackground(Object... params) {
482 Object account = params[0];
483 if (account instanceof OwnCloudAccount){
484 try {
485 OwnCloudAccount ocAccount = (OwnCloudAccount) account;
486 return OwnCloudClientManagerFactory.getDefaultSingleton().
487 getClientFor(ocAccount, MainApp.getAppContext());
488 } catch (AccountUtils.AccountNotFoundException e) {
489 e.printStackTrace();
490 } catch (OperationCanceledException e) {
491 e.printStackTrace();
492 } catch (AuthenticatorException e) {
493 e.printStackTrace();
494 } catch (IOException e) {
495 e.printStackTrace();
496 }
497 }
498
499 return null;
500 }
501 }
502
503
504 private class VideoHelper implements OnCompletionListener, OnPreparedListener, OnErrorListener {
505
506 /**
507 * Called when the file is ready to be played.
508 * <p/>
509 * Just starts the playback.
510 *
511 * @param vp {@link MediaPlayer} instance performing the playback.
512 */
513 @Override
514 public void onPrepared(MediaPlayer vp) {
515 Log_OC.v(TAG, "onPrepared");
516 mVideoPreview.seekTo(mSavedPlaybackPosition);
517 if (mAutoplay) {
518 mVideoPreview.start();
519 }
520 mMediaController.setEnabled(true);
521 mMediaController.updatePausePlay();
522 mPrepared = true;
523 }
524
525
526 /**
527 * Called when the file is finished playing.
528 * <p/>
529 * Finishes the activity.
530 *
531 * @param mp {@link MediaPlayer} instance performing the playback.
532 */
533 @Override
534 public void onCompletion(MediaPlayer mp) {
535 Log_OC.v(TAG, "completed");
536 if (mp != null) {
537 mVideoPreview.seekTo(0);
538 } // else : called from onError()
539 mMediaController.updatePausePlay();
540 }
541
542
543 /**
544 * Called when an error in playback occurs.
545 *
546 * @param mp {@link MediaPlayer} instance performing the playback.
547 * @param what Type of error
548 * @param extra Extra code specific to the error
549 */
550 @Override
551 public boolean onError(MediaPlayer mp, int what, int extra) {
552 MediaService.streamWithExternalApp(mUri, getActivity()).show();
553 return true;
554 }
555 }
556
557 @Override
558 public void onPause() {
559 Log_OC.v(TAG, "onPause");
560 super.onPause();
561 }
562
563 @Override
564 public void onResume() {
565 super.onResume();
566 Log_OC.v(TAG, "onResume");
567 }
568
569 @Override
570 public void onDestroy() {
571 Log_OC.v(TAG, "onDestroy");
572 super.onDestroy();
573 }
574
575 @Override
576 public void onStop() {
577 Log_OC.v(TAG, "onStop");
578
579 mPrepared = false;
580 if (mMediaServiceConnection != null) {
581 Log_OC.d(TAG, "Unbinding from MediaService ...");
582 if (mMediaServiceBinder != null && mMediaController != null) {
583 mMediaServiceBinder.unregisterMediaController(mMediaController);
584 }
585 getActivity().unbindService(mMediaServiceConnection);
586 mMediaServiceConnection = null;
587 mMediaServiceBinder = null;
588 }
589
590 super.onStop();
591 }
592
593 @Override
594 public boolean onTouch(View v, MotionEvent event) {
595 if (event.getAction() == MotionEvent.ACTION_DOWN && v == mVideoPreview) {
596 // added a margin on the left to avoid interfering with gesture to open navigation drawer
597 if (event.getX() / Resources.getSystem().getDisplayMetrics().density > 24.0) {
598 startFullScreenVideo();
599 }
600 return true;
601 }
602 return false;
603 }
604
605
606 private void startFullScreenVideo() {
607 Intent i = new Intent(getActivity(), PreviewVideoActivity.class);
608 i.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
609 i.putExtra(FileActivity.EXTRA_FILE, getFile());
610 i.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, mVideoPreview.isPlaying());
611 mVideoPreview.pause();
612 i.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, mVideoPreview.getCurrentPosition());
613 startActivityForResult(i, 0);
614 }
615
616 @Override
617 public void onConfigurationChanged(Configuration newConfig) {
618 Log_OC.v(TAG, "onConfigurationChanged " + this);
619 }
620
621 @Override
622 public void onActivityResult(int requestCode, int resultCode, Intent data) {
623 Log_OC.v(TAG, "onActivityResult " + this);
624 super.onActivityResult(requestCode, resultCode, data);
625 if (resultCode == Activity.RESULT_OK) {
626 mSavedPlaybackPosition = data.getExtras().getInt(
627 PreviewVideoActivity.EXTRA_START_POSITION);
628 mAutoplay = data.getExtras().getBoolean(PreviewVideoActivity.EXTRA_AUTOPLAY);
629 }
630 }
631
632
633 private void playAudio() {
634 OCFile file = getFile();
635 if (!mMediaServiceBinder.isPlaying(file)) {
636 Log_OC.d(TAG, "starting playback of " + file.getStoragePath());
637 mMediaServiceBinder.start(mAccount, file, mAutoplay, mSavedPlaybackPosition);
638
639 }
640 else {
641 if (!mMediaServiceBinder.isPlaying() && mAutoplay) {
642 mMediaServiceBinder.start();
643 mMediaController.updatePausePlay();
644 }
645 }
646 }
647
648
649 private void bindMediaService() {
650 Log_OC.d(TAG, "Binding to MediaService...");
651 if (mMediaServiceConnection == null) {
652 mMediaServiceConnection = new MediaServiceConnection();
653 }
654 getActivity().bindService( new Intent(getActivity(),
655 MediaService.class),
656 mMediaServiceConnection,
657 Context.BIND_AUTO_CREATE);
658 // follow the flow in MediaServiceConnection#onServiceConnected(...)
659 }
660
661 /** Defines callbacks for service binding, passed to bindService() */
662 private class MediaServiceConnection implements ServiceConnection {
663
664 @Override
665 public void onServiceConnected(ComponentName component, IBinder service) {
666 if (getActivity() != null) {
667 if (component.equals(
668 new ComponentName(getActivity(), MediaService.class))) {
669 Log_OC.d(TAG, "Media service connected");
670 mMediaServiceBinder = (MediaServiceBinder) service;
671 if (mMediaServiceBinder != null) {
672 prepareMediaController();
673 playAudio(); // do not wait for the touch of nobody to play audio
674
675 Log_OC.d(TAG, "Successfully bound to MediaService, MediaController ready");
676
677 }
678 else {
679 Log_OC.e(TAG, "Unexpected response from MediaService while binding");
680 }
681 }
682 }
683 }
684
685 private void prepareMediaController() {
686 mMediaServiceBinder.registerMediaController(mMediaController);
687 if (mMediaController != null) {
688 mMediaController.setMediaPlayer(mMediaServiceBinder);
689 mMediaController.setEnabled(true);
690 mMediaController.updatePausePlay();
691 }
692 }
693
694 @Override
695 public void onServiceDisconnected(ComponentName component) {
696 if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
697 Log_OC.w(TAG, "Media service suddenly disconnected");
698 if (mMediaController != null) {
699 mMediaController.setMediaPlayer(null);
700 }
701 else {
702 Toast.makeText(
703 getActivity(),
704 "No media controller to release when disconnected from media service",
705 Toast.LENGTH_SHORT).show();
706 }
707 mMediaServiceBinder = null;
708 mMediaServiceConnection = null;
709 }
710 }
711 }
712
713
714 /**
715 * Opens the previewed file with an external application.
716 */
717 private void openFile() {
718 stopPreview(true);
719 mContainerActivity.getFileOperationsHelper().openFile(getFile());
720 finish();
721 }
722
723 /**
724 * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment}
725 * to be previewed.
726 *
727 * @param file File to test if can be previewed.
728 * @return 'True' if the file can be handled by the fragment.
729 */
730 public static boolean canBePreviewed(OCFile file) {
731 return (file != null && (file.isAudio() || file.isVideo()));
732 }
733
734
735 public void stopPreview(boolean stopAudio) {
736 OCFile file = getFile();
737 if (file.isAudio() && stopAudio) {
738 mMediaServiceBinder.pause();
739
740 }
741 else {
742 if (file.isVideo()) {
743 mVideoPreview.stopPlayback();
744 }
745 }
746 }
747
748
749 /**
750 * Finishes the preview
751 */
752 private void finish() {
753 getActivity().onBackPressed();
754 }
755
756
757 public int getPosition() {
758 if (mPrepared) {
759 mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
760 }
761 Log_OC.v(TAG, "getting position: " + mSavedPlaybackPosition);
762 return mSavedPlaybackPosition;
763 }
764
765 public boolean isPlaying() {
766 if (mPrepared) {
767 mAutoplay = mVideoPreview.isPlaying();
768 }
769 return mAutoplay;
770 }
771
772 }