1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package com
.owncloud
.android
.ui
.preview
;
20 import java
.util
.ArrayList
;
21 import java
.util
.List
;
23 import android
.accounts
.Account
;
24 import android
.app
.Activity
;
25 import android
.app
.AlertDialog
;
26 import android
.content
.ActivityNotFoundException
;
27 import android
.content
.ComponentName
;
28 import android
.content
.Context
;
29 import android
.content
.DialogInterface
;
30 import android
.content
.Intent
;
31 import android
.content
.ServiceConnection
;
32 import android
.content
.res
.Configuration
;
33 import android
.media
.MediaPlayer
;
34 import android
.media
.MediaPlayer
.OnCompletionListener
;
35 import android
.media
.MediaPlayer
.OnErrorListener
;
36 import android
.media
.MediaPlayer
.OnPreparedListener
;
37 import android
.net
.Uri
;
38 import android
.os
.Build
;
39 import android
.os
.Bundle
;
40 import android
.os
.Handler
;
41 import android
.os
.IBinder
;
42 import android
.view
.LayoutInflater
;
43 import android
.view
.MotionEvent
;
44 import android
.view
.View
;
45 import android
.view
.View
.OnTouchListener
;
46 import android
.view
.ViewGroup
;
47 import android
.webkit
.MimeTypeMap
;
48 import android
.widget
.ImageView
;
49 import android
.widget
.Toast
;
50 import android
.widget
.VideoView
;
52 import com
.actionbarsherlock
.view
.Menu
;
53 import com
.actionbarsherlock
.view
.MenuInflater
;
54 import com
.actionbarsherlock
.view
.MenuItem
;
55 import com
.owncloud
.android
.Log_OC
;
56 import com
.owncloud
.android
.R
;
57 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
58 import com
.owncloud
.android
.datamodel
.OCFile
;
59 import com
.owncloud
.android
.media
.MediaControlView
;
60 import com
.owncloud
.android
.media
.MediaService
;
61 import com
.owncloud
.android
.media
.MediaServiceBinder
;
62 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
;
63 import com
.owncloud
.android
.operations
.RemoteOperation
;
64 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
65 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
66 import com
.owncloud
.android
.ui
.activity
.FileActivity
;
67 import com
.owncloud
.android
.ui
.activity
.FileDisplayActivity
;
68 import com
.owncloud
.android
.ui
.fragment
.ConfirmationDialogFragment
;
69 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
71 import eu
.alefzero
.webdav
.WebdavUtils
;
74 * This fragment shows a preview of a downloaded media file (audio or video).
76 * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will produce an {@link IllegalStateException}.
78 * By now, if the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is generated on instantiation too.
80 * @author David A. Velasco
82 public class PreviewMediaFragment
extends FileFragment
implements
84 ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
, OnRemoteOperationListener
{
86 public static final String EXTRA_FILE
= "FILE";
87 public static final String EXTRA_ACCOUNT
= "ACCOUNT";
88 private static final String EXTRA_PLAY_POSITION
= "PLAY_POSITION";
89 private static final String EXTRA_PLAYING
= "PLAYING";
92 private Account mAccount
;
93 private FileDataStorageManager mStorageManager
;
94 private ImageView mImagePreview
;
95 private VideoView mVideoPreview
;
96 private int mSavedPlaybackPosition
;
98 private Handler mHandler
;
99 private RemoteOperation mLastRemoteOperation
;
101 private MediaServiceBinder mMediaServiceBinder
= null
;
102 private MediaControlView mMediaController
= null
;
103 private MediaServiceConnection mMediaServiceConnection
= null
;
104 private VideoHelper mVideoHelper
;
105 private boolean mAutoplay
;
106 public boolean mPrepared
;
108 private static final String TAG
= PreviewMediaFragment
.class.getSimpleName();
112 * Creates a fragment to preview a file.
114 * When 'fileToDetail' or 'ocAccount' are null
116 * @param fileToDetail An {@link OCFile} to preview in the fragment
117 * @param ocAccount An ownCloud account; needed to start downloads
119 public PreviewMediaFragment(OCFile fileToDetail
, Account ocAccount
, int startPlaybackPosition
, boolean autoplay
) {
121 mAccount
= ocAccount
;
122 mSavedPlaybackPosition
= startPlaybackPosition
;
123 mStorageManager
= null
; // we need a context to init this; the container activity is not available yet at this moment
124 mAutoplay
= autoplay
;
129 * Creates an empty fragment for previews.
131 * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically (for instance, when the device is turned a aside).
133 * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction
135 public PreviewMediaFragment() {
138 mSavedPlaybackPosition
= 0;
139 mStorageManager
= null
;
148 public void onCreate(Bundle savedInstanceState
) {
149 super.onCreate(savedInstanceState
);
150 mHandler
= new Handler();
151 setHasOptionsMenu(true
);
159 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
160 Bundle savedInstanceState
) {
161 super.onCreateView(inflater
, container
, savedInstanceState
);
162 Log_OC
.e(TAG
, "onCreateView");
165 mView
= inflater
.inflate(R
.layout
.file_preview
, container
, false
);
167 mImagePreview
= (ImageView
)mView
.findViewById(R
.id
.image_preview
);
168 mVideoPreview
= (VideoView
)mView
.findViewById(R
.id
.video_preview
);
169 mVideoPreview
.setOnTouchListener(this);
171 mMediaController
= (MediaControlView
)mView
.findViewById(R
.id
.media_controller
);
181 public void onAttach(Activity activity
) {
182 super.onAttach(activity
);
183 Log_OC
.e(TAG
, "onAttach");
185 if (!(activity
instanceof FileFragment
.ContainerActivity
))
186 throw new ClassCastException(activity
.toString() + " must implement " + FileFragment
.ContainerActivity
.class.getSimpleName());
194 public void onActivityCreated(Bundle savedInstanceState
) {
195 super.onActivityCreated(savedInstanceState
);
196 Log_OC
.e(TAG
, "onActivityCreated");
198 mStorageManager
= new FileDataStorageManager(mAccount
, getActivity().getApplicationContext().getContentResolver());
199 if (savedInstanceState
!= null
) {
200 setFile((OCFile
)savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_FILE
));
201 mAccount
= savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
);
202 mSavedPlaybackPosition
= savedInstanceState
.getInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
);
203 mAutoplay
= savedInstanceState
.getBoolean(PreviewMediaFragment
.EXTRA_PLAYING
);
206 OCFile file
= getFile();
208 throw new IllegalStateException("Instanced with a NULL OCFile");
210 if (mAccount
== null
) {
211 throw new IllegalStateException("Instanced with a NULL ownCloud Account");
213 if (!file
.isDown()) {
214 throw new IllegalStateException("There is no local file to preview");
216 if (file
.isVideo()) {
217 mVideoPreview
.setVisibility(View
.VISIBLE
);
218 mImagePreview
.setVisibility(View
.GONE
);
222 mVideoPreview
.setVisibility(View
.GONE
);
223 mImagePreview
.setVisibility(View
.VISIBLE
);
233 public void onSaveInstanceState(Bundle outState
) {
234 super.onSaveInstanceState(outState
);
235 Log_OC
.e(TAG
, "onSaveInstanceState");
237 outState
.putParcelable(PreviewMediaFragment
.EXTRA_FILE
, getFile());
238 outState
.putParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
, mAccount
);
240 if (getFile().isVideo()) {
241 mSavedPlaybackPosition
= mVideoPreview
.getCurrentPosition();
242 mAutoplay
= mVideoPreview
.isPlaying();
243 outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
, mSavedPlaybackPosition
);
244 outState
.putBoolean(PreviewMediaFragment
.EXTRA_PLAYING
, mAutoplay
);
246 outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
, mMediaServiceBinder
.getCurrentPosition());
247 outState
.putBoolean(PreviewMediaFragment
.EXTRA_PLAYING
, mMediaServiceBinder
.isPlaying());
253 public void onStart() {
255 Log_OC
.e(TAG
, "onStart");
257 OCFile file
= getFile();
259 if (file
.isAudio()) {
262 } else if (file
.isVideo()) {
270 private void stopAudio() {
271 Intent i
= new Intent(getSherlockActivity(), MediaService
.class);
272 i
.setAction(MediaService
.ACTION_STOP_ALL
);
273 getSherlockActivity().startService(i
);
281 public void onCreateOptionsMenu(Menu menu
, MenuInflater inflater
) {
282 super.onCreateOptionsMenu(menu
, inflater
);
284 inflater
.inflate(R
.menu
.file_actions_menu
, menu
);
285 List
<Integer
> toHide
= new ArrayList
<Integer
>();
287 MenuItem item
= null
;
288 toHide
.add(R
.id
.action_cancel_download
);
289 toHide
.add(R
.id
.action_cancel_upload
);
290 toHide
.add(R
.id
.action_download_file
);
291 toHide
.add(R
.id
.action_sync_file
);
292 toHide
.add(R
.id
.action_rename_file
); // by now
294 for (int i
: toHide
) {
295 item
= menu
.findItem(i
);
297 item
.setVisible(false
);
298 item
.setEnabled(false
);
309 public boolean onOptionsItemSelected(MenuItem item
) {
310 switch (item
.getItemId()) {
311 case R
.id
.action_open_file_with
: {
315 case R
.id
.action_remove_file
: {
319 case R
.id
.action_see_details
: {
330 private void seeDetails() {
332 ((FileFragment
.ContainerActivity
)getActivity()).showDetails(getFile());
336 private void prepareVideo() {
337 // create helper to get more control on the playback
338 mVideoHelper
= new VideoHelper();
339 mVideoPreview
.setOnPreparedListener(mVideoHelper
);
340 mVideoPreview
.setOnCompletionListener(mVideoHelper
);
341 mVideoPreview
.setOnErrorListener(mVideoHelper
);
344 private void playVideo() {
345 // create and prepare control panel for the user
346 mMediaController
.setMediaPlayer(mVideoPreview
);
348 // load the video file in the video player ; when done, VideoHelper#onPrepared() will be called
349 mVideoPreview
.setVideoPath(getFile().getStoragePath());
353 private class VideoHelper
implements OnCompletionListener
, OnPreparedListener
, OnErrorListener
{
356 * Called when the file is ready to be played.
358 * Just starts the playback.
360 * @param mp {@link MediaPlayer} instance performing the playback.
363 public void onPrepared(MediaPlayer vp
) {
364 Log_OC
.e(TAG
, "onPrepared");
365 mVideoPreview
.seekTo(mSavedPlaybackPosition
);
367 mVideoPreview
.start();
369 mMediaController
.setEnabled(true
);
370 mMediaController
.updatePausePlay();
376 * Called when the file is finished playing.
378 * Finishes the activity.
380 * @param mp {@link MediaPlayer} instance performing the playback.
383 public void onCompletion(MediaPlayer mp
) {
384 Log_OC
.e(TAG
, "completed");
386 mVideoPreview
.seekTo(0);
387 // next lines are necessary to work around undesired video loops
388 if (Build
.VERSION
.SDK_INT
== Build
.VERSION_CODES
.GINGERBREAD
) {
389 mVideoPreview
.pause();
391 } else if (Build
.VERSION
.SDK_INT
== Build
.VERSION_CODES
.GINGERBREAD_MR1
) {
392 // mVideePreview.pause() is not enough
394 mMediaController
.setEnabled(false
);
395 mVideoPreview
.stopPlayback();
397 mSavedPlaybackPosition
= 0;
398 mVideoPreview
.setVideoPath(getFile().getStoragePath());
400 } // else : called from onError()
401 mMediaController
.updatePausePlay();
406 * Called when an error in playback occurs.
408 * @param mp {@link MediaPlayer} instance performing the playback.
409 * @param what Type of error
410 * @param extra Extra code specific to the error
413 public boolean onError(MediaPlayer mp
, int what
, int extra
) {
414 if (mVideoPreview
.getWindowToken() != null
) {
415 String message
= MediaService
.getMessageForMediaError(getActivity(), what
, extra
);
416 new AlertDialog
.Builder(getActivity())
418 .setPositiveButton(android
.R
.string
.VideoView_error_button
,
419 new DialogInterface
.OnClickListener() {
420 public void onClick(DialogInterface dialog
, int whichButton
) {
422 VideoHelper
.this.onCompletion(null
);
425 .setCancelable(false
)
435 public void onPause() {
437 Log_OC
.e(TAG
, "onPause");
441 public void onResume() {
443 Log_OC
.e(TAG
, "onResume");
447 public void onDestroy() {
449 Log_OC
.e(TAG
, "onDestroy");
453 public void onStop() {
454 Log_OC
.e(TAG
, "onStop");
458 if (mMediaServiceConnection
!= null
) {
459 Log_OC
.d(TAG
, "Unbinding from MediaService ...");
460 if (mMediaServiceBinder
!= null
&& mMediaController
!= null
) {
461 mMediaServiceBinder
.unregisterMediaController(mMediaController
);
463 getActivity().unbindService(mMediaServiceConnection
);
464 mMediaServiceConnection
= null
;
465 mMediaServiceBinder
= null
;
470 public boolean onTouch(View v
, MotionEvent event
) {
471 if (event
.getAction() == MotionEvent
.ACTION_DOWN
&& v
== mVideoPreview
) {
472 startFullScreenVideo();
479 private void startFullScreenVideo() {
480 Intent i
= new Intent(getActivity(), PreviewVideoActivity
.class);
481 i
.putExtra(FileActivity
.EXTRA_ACCOUNT
, mAccount
);
482 i
.putExtra(FileActivity
.EXTRA_FILE
, getFile());
483 i
.putExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, mVideoPreview
.isPlaying());
484 mVideoPreview
.pause();
485 i
.putExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, mVideoPreview
.getCurrentPosition());
486 startActivityForResult(i
, 0);
490 public void onConfigurationChanged (Configuration newConfig
) {
491 Log_OC
.e(TAG
, "onConfigurationChanged " + this);
495 public void onActivityResult (int requestCode
, int resultCode
, Intent data
) {
496 Log_OC
.e(TAG
, "onActivityResult " + this);
497 super.onActivityResult(requestCode
, resultCode
, data
);
498 if (resultCode
== Activity
.RESULT_OK
) {
499 mSavedPlaybackPosition
= data
.getExtras().getInt(PreviewVideoActivity
.EXTRA_START_POSITION
);
500 mAutoplay
= data
.getExtras().getBoolean(PreviewVideoActivity
.EXTRA_AUTOPLAY
);
505 private void playAudio() {
506 OCFile file
= getFile();
507 if (!mMediaServiceBinder
.isPlaying(file
)) {
508 Log_OC
.d(TAG
, "starting playback of " + file
.getStoragePath());
509 mMediaServiceBinder
.start(mAccount
, file
, mAutoplay
, mSavedPlaybackPosition
);
512 if (!mMediaServiceBinder
.isPlaying() && mAutoplay
) {
513 mMediaServiceBinder
.start();
514 mMediaController
.updatePausePlay();
520 private void bindMediaService() {
521 Log_OC
.d(TAG
, "Binding to MediaService...");
522 if (mMediaServiceConnection
== null
) {
523 mMediaServiceConnection
= new MediaServiceConnection();
525 getActivity().bindService( new Intent(getActivity(),
527 mMediaServiceConnection
,
528 Context
.BIND_AUTO_CREATE
);
529 // follow the flow in MediaServiceConnection#onServiceConnected(...)
532 /** Defines callbacks for service binding, passed to bindService() */
533 private class MediaServiceConnection
implements ServiceConnection
{
536 public void onServiceConnected(ComponentName component
, IBinder service
) {
537 if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) {
538 Log_OC
.d(TAG
, "Media service connected");
539 mMediaServiceBinder
= (MediaServiceBinder
) service
;
540 if (mMediaServiceBinder
!= null
) {
541 prepareMediaController();
542 playAudio(); // do not wait for the touch of nobody to play audio
544 Log_OC
.d(TAG
, "Successfully bound to MediaService, MediaController ready");
547 Log_OC
.e(TAG
, "Unexpected response from MediaService while binding");
552 private void prepareMediaController() {
553 mMediaServiceBinder
.registerMediaController(mMediaController
);
554 if (mMediaController
!= null
) {
555 mMediaController
.setMediaPlayer(mMediaServiceBinder
);
556 mMediaController
.setEnabled(true
);
557 mMediaController
.updatePausePlay();
562 public void onServiceDisconnected(ComponentName component
) {
563 if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) {
564 Log_OC
.e(TAG
, "Media service suddenly disconnected");
565 if (mMediaController
!= null
) {
566 mMediaController
.setMediaPlayer(null
);
568 Toast
.makeText(getActivity(), "No media controller to release when disconnected from media service", Toast
.LENGTH_SHORT
).show();
570 mMediaServiceBinder
= null
;
571 mMediaServiceConnection
= null
;
579 * Opens the previewed file with an external application.
581 * TODO - improve this; instead of prioritize the actions available for the MIME type in the server,
582 * we should get a list of available apps for MIME tpye in the server and join it with the list of
583 * available apps for the MIME type known from the file extension, to let the user choose
585 private void openFile() {
586 OCFile file
= getFile();
588 String storagePath
= file
.getStoragePath();
589 String encodedStoragePath
= WebdavUtils
.encodePath(storagePath
);
591 Intent i
= new Intent(Intent
.ACTION_VIEW
);
592 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), file
.getMimetype());
593 i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
);
596 } catch (Throwable t
) {
597 Log_OC
.e(TAG
, "Fail when trying to open with the mimeType provided from the ownCloud server: " + file
.getMimetype());
598 boolean toastIt
= true
;
599 String mimeType
= "";
601 Intent i
= new Intent(Intent
.ACTION_VIEW
);
602 mimeType
= MimeTypeMap
.getSingleton().getMimeTypeFromExtension(storagePath
.substring(storagePath
.lastIndexOf('.') + 1));
603 if (mimeType
== null
|| !mimeType
.equals(file
.getMimetype())) {
604 if (mimeType
!= null
) {
605 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), mimeType
);
608 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), "*-/*");
610 i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
);
615 } catch (IndexOutOfBoundsException e
) {
616 Log_OC
.e(TAG
, "Trying to find out MIME type of a file without extension: " + storagePath
);
618 } catch (ActivityNotFoundException e
) {
619 Log_OC
.e(TAG
, "No activity found to handle: " + storagePath
+ " with MIME type " + mimeType
+ " obtained from extension");
621 } catch (Throwable th
) {
622 Log_OC
.e(TAG
, "Unexpected problem when opening: " + storagePath
, th
);
626 Toast
.makeText(getActivity(), "There is no application to handle file " + file
.getFileName(), Toast
.LENGTH_SHORT
).show();
635 * Starts a the removal of the previewed file.
637 * Shows a confirmation dialog. The action continues in {@link #onConfirmation(String)} , {@link #onNeutral(String)} or {@link #onCancel(String)},
638 * depending upon the user selection in the dialog.
640 private void removeFile() {
641 ConfirmationDialogFragment confDialog
= ConfirmationDialogFragment
.newInstance(
642 R
.string
.confirmation_remove_alert
,
643 new String
[]{getFile().getFileName()},
644 R
.string
.confirmation_remove_remote_and_local
,
645 R
.string
.confirmation_remove_local
,
646 R
.string
.common_cancel
);
647 confDialog
.setOnConfirmationListener(this);
648 confDialog
.show(getFragmentManager(), ConfirmationDialogFragment
.FTAG_CONFIRMATION
);
653 * Performs the removal of the previewed file, both locally and in the server.
656 public void onConfirmation(String callerTag
) {
657 OCFile file
= getFile();
658 if (mStorageManager
.getFileById(file
.getFileId()) != null
) { // check that the file is still there;
660 mLastRemoteOperation
= new RemoveFileOperation( file
, // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
663 mLastRemoteOperation
.execute(mAccount
, getSherlockActivity(), this, mHandler
, getSherlockActivity());
665 ((FileDisplayActivity
) getActivity()).showLoadingDialog();
671 * Removes the file from local storage
674 public void onNeutral(String callerTag
) {
675 // TODO this code should be made in a secondary thread,
676 OCFile file
= getFile();
677 if (file
.isDown()) { // checks it is still there
679 File f
= new File(file
.getStoragePath());
681 file
.setStoragePath(null
);
682 mStorageManager
.saveFile(file
);
688 * User cancelled the removal action.
691 public void onCancel(String callerTag
) {
692 // nothing to do here
697 * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} to be previewed.
699 * @param file File to test if can be previewed.
700 * @return 'True' if the file can be handled by the fragment.
702 public static boolean canBePreviewed(OCFile file
) {
703 return (file
!= null
&& (file
.isAudio() || file
.isVideo()));
710 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
711 if (operation
.equals(mLastRemoteOperation
)) {
712 if (operation
instanceof RemoveFileOperation
) {
713 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
718 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
719 ((FileDisplayActivity
) getActivity()).dismissLoadingDialog();
720 if (result
.isSuccess()) {
721 Toast msg
= Toast
.makeText(getActivity().getApplicationContext(), R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
726 Toast msg
= Toast
.makeText(getActivity(), R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
728 if (result
.isSslRecoverableException()) {
729 // TODO show the SSL warning dialog
734 private void stopPreview(boolean stopAudio
) {
735 OCFile file
= getFile();
736 if (file
.isAudio() && stopAudio
) {
737 mMediaServiceBinder
.pause();
739 } else if (file
.isVideo()) {
740 mVideoPreview
.stopPlayback();
747 * Finishes the preview
749 private void finish() {
750 getActivity().onBackPressed();
754 public int getPosition() {
756 mSavedPlaybackPosition
= mVideoPreview
.getCurrentPosition();
758 Log_OC
.e(TAG
, "getting position: " + mSavedPlaybackPosition
);
759 return mSavedPlaybackPosition
;
762 public boolean isPlaying() {
764 mAutoplay
= mVideoPreview
.isPlaying();